basically ive followed this tutorial here
and have everything up and running and working fine off my local machine. I have deployed it in IIS and allowed necessary Firewall ports so off i go to my client PC which resides on a different domain.
I fired up the WCF Test client on this machine and typed in the URL for the WSDL and i was able to view the service calls no problem. Only thing is when i actually try to use the method and send off my values i get the following response
"The Caller Was Not Authenticated By The Service"
Weird - even though it still works locally it wont work on another machine. Is there a specific way to configure the client based on what im doing??
here is my web.config
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="WCF33.Service1">
<endpoint address ="" binding="wsHttpBinding" contract="WCF33.IService1" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/WCF33/Service1/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
The tutorial i followed passes a key in the message header and authenticates based on that but thats not the issue. I think its something to do with the wshttp binding but i do need this type of encryption.
can anyone give me any info/advice on how to resolve this please :)
The tutorial i followed passes a key in the message header and authenticates based on that but thats not the issue.
Are you passing the key in your call? If the code you have running is expecting something in the authentication header and it's not there that could cause that error to return.
Ok i now have this sorted, i had two main issues with this, this question actually ended up being my first hurdle.
With wshttpbinding i had to configure a client programatically, creating a wshttpbinding and attaching it to an instance of the service. I also had to pass windows credentials. Once i did this, the caller was authenticated message disappeared.
The next stage of the error was a application/xml error where the expected response didnt match soap 1.2 formatting. This was a strange one because for some reason even though the binding server side was wshttp, it was defaulting to basichttp on deployment. To get around this there is a mapping section in the wcf config editor where you can map protocols to a binding. In this, http is set to basichttp, simply change this to wshttp an you are good to go :)
hope this helps someone because these two errors seem to be everywhere with no answers at all!!
Related
I have simple client app (console application) and server app (WCF library project) using WCF. I want to see how WCF messages looks like in Fiddler.
I added following code to client's app.config:
<configuration>
<system.net>
<defaultProxy>
<proxy bypassonlocal="False" usesystemdefault="True" proxyaddress="http://127.0.0.1:8888" />
</defaultProxy>
</system.net>
My Fiddler shows all connections from browsers except one having word "vshub" in url, but there are no connections between WCF client/server apps displayed. How to configure it?
UPDATE1:
My WCF service library (server application) is configured in following way:
<system.serviceModel>
<services>
<service name="WcfServer.Service1">
<host>
<baseAddresses>
<add baseAddress = "http://localhost:8733/Design_Time_Addresses/WcfServer/Service1/" />
</baseAddresses>
</host>
<!-- Service Endpoints -->
<!-- Unless fully qualified, address is relative to base address supplied above -->
<endpoint address="" binding="basicHttpBinding" contract="WcfServer.IService1">
<!--
Upon deployment, the following identity element should be removed or replaced to reflect the
identity under which the deployed service runs. If removed, WCF will infer an appropriate identity
automatically.
-->
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<!-- Metadata Endpoints -->
<!-- The Metadata Exchange endpoint is used by the service to describe itself to clients. -->
<!-- This endpoint does not use a secure binding and should be secured or removed before deployment -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information,
set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True"/>
<!-- To receive exception details in faults for debugging purposes,
set the value below to true. Set to false before deployment
to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
you have nothing to do in the client config and you can remove your proxy settings. Fiddler will work if you do not use "localhost" and replace it with "MyMachineName"
Local requests aren't catched by Fiddler. Fiddler only catches requests that actually go over the wire. Local requests are shortcutted by Windows.
There is an old post with some alternatives, although I don't know how actual that list is.
I have a WCF Service Application running that requires byte arrays to be sent to the service and be returned from the service. I am getting the 413 "Request Too Large" error. I have researched this error and there are many responses like changing the binding element to include maxReceivedMessageSize, adding the readerQuotes element to the binding element with settings and other changes. However, my web.config does not have the binding element. I changed it on the client side but this made no difference. It would make since that the server side (were the service runs) would be where these settings need to be done at. I am at a loss as to where I make the changes on the server side. What settings am I missing to take care of sending and receiving larger byte arrays? Here is the web.config the server is using:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
</system.web>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the values below to false before deployment -->
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information -->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<!--
To browse web app root directory during debugging, set the value below to true.
Set to false before deployment to avoid disclosing web app folder information.
-->
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
Starting with WCF 4.0, by default (with no endpoints or bindings explicitly defined) WCF will create default endpoints with basicHttpBinding. This makes the configuration less cluttered, but also means you get the default values for the binding. There are two ways to resolve this when you need non-default settings for a binding (on the service side):
First, you can add a default binding configuration by ommitting the name attribute, like this:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding closeTimeout="........... />
</basicHttpBinding>
</bindings>
Or, you can name your binding configuration and then create an explicit endpoint that uses that configuration:
<system.serviceModel>
<services>
<service name=".....>
<endpoint address="" bindingConfiguration="MyBasicHttpBinding"..... />
The second example assumes you have a binding configuration named "MyBasicHttpBinding" in your bindings section.
I've ommitted a good deal of the configuration for simplicity. Let me know if you need further details.
https://stackoverflow.com/a/884248/78551 is an accepted answer to this question. The server side will have a similar configuration set up.
I had this issue once due to trying to pull back huge datasets from entity framework. There is a limit and those kinds of things will HEAVILY affect how much data you can push through.
I broke my requests up. GetProducts, GetOrders, GetContracts, etc. Then on the client side I stitched them all together. I do NOT condone doing this but I was forced to handle such HUGE datasets by my architect.
Sometimes you just cannot get around the imposed limits of the framework/platform.
Also, have you looked at other protocols to use like net.tcp (if I recall correctly) that would open a socket and stream the data?
IIS 7.0 on Windows 2008
WCF Web Service, .NET 4 from VS 2010
Web service is installed via publishing and I have full admin rights on the server. There are several complicated methods, but there is a simple one that returns the build version. If we can get this one working, I can fix them all - here is my interface:
namespace MyNameSpace
{
[ServiceContract]
public interface WebInterface
{
[OperationContract]
[WebGet]
string GetVersion();
Attempt to connect via HTTP:// and everything works fine!
Attempt to conenct via HTTPS:// I get a 404 file not found.
I can reach the generic "You have created a web service..." page, including full web service path and the C# generic sample code when browsing to the exact same URL's both on HTTP and HTTPS.
In C#, I have read that the certificate can cause trouble, and I have already implemented the delegate overload to approve our server certificate.
I suspect missing one or more entries in the Web.config file, but I don't have a clue where to start. I have tried Google searching and Stack Overflow searching, but I haven't found the correct combination of search terms to help with this particular issue.
Web Config:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="HttpGetMetadata">
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service name="LinkService" behaviorConfiguration="HttpGetMetadata">
<endpoint address="" contract="WebInterface" binding="basicHttpBinding" />
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Help Please.
You're using the defaults for basicHttpBinding, and the default security mode for that binding is None. You need to define the binding and set the security mode to Transport in your config. Add a Bindings section to your ServiceModel section, like this:
<serviceModel>
<Bindings>
<basicHttpBinding name="secureBinding">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
</basicHttpBinding>
</Bindings>
</serviceModel>
Then you need to assign this binding to your endpoint via the bindingConfiguration attribute, like this:
<endpoint address=""
binding="basicHttpBinding"
bindingConfiguration="secureBinding"
contract="WebInterface" />
You'll probably want to enable httpsGetEnabled as well:
<serviceMetadata httpGetEnabled="true"
httpsGetEnabled="true" />
See BasicBinding with Transport Security (which is what the sample code is based on).
You can also google with terms like "BasicHttpBinding WCF SSL" and stuff like that - lots of examples and information on the web, it's just a matter of using the right words :)
Also, I'm not 100% confident that the transportClientCredential setting is correct for your scenario (it might need to be Certificate), but I've done very little with SSL for WCF.
There may be other issues as well (like how IIS is set up on your machine), but the above is what's needed for the config.
I have a simple WCF service that uses WSHttpBinding and Windows authentication. I'm trying to force the server to impersonate the client's identity upon every method call for this service.
I tried the advice given at WCF Service Impersonation, but am not exactly getting happy results. When I try to navigate to the landing page for the WCF service, I see the error:
The contract operation 'GetAdvice'
requires Windows identity for
automatic impersonation. A Windows
identity that represents the caller is
not provided by binding
('WSHttpBinding','http://tempuri.org/')
for contract
('IMagicEightBallService','http://tempuri.org/'.
Any ideas on what this error's trying to tell me?
The entire solution can be browsed at ftp://petio.org/2011/07/01/MagicEightBall/ (or downloaded at http://petio.org/2011/07/01/MagicEightBall.zip). I'm just publishing the project to a local IIS folder and accessing the service at http://localhost/MagicEightBall/MagicEightBallService.svc.
Thanks!
UPDATE:
My service's Web.config:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
</system.web>
<system.serviceModel>
<services>
<service name="Petio.MagicEightBall.MagicEightBallService" behaviorConfiguration="MagicEightBallServiceBehavior">
<endpoint name="WSHttpBinding_WindowsSecurity_IMagicEightBallService"
address="http://localhost/MagicEightBall/MagicEightBallService.svc"
binding="wsHttpBinding"
contract="Petio.MagicEightBall.IMagicEightBallService" />
<endpoint address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MagicEightBallServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
<serviceAuthorization impersonateCallerForAllOperations="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
My service code:
public class MagicEightBallService : IMagicEightBallService
{
[OperationBehavior(Impersonation=ImpersonationOption.Required)]
public string GetAdvice()
{
MagicEightBall ball = new MagicEightBall();
return ball.GetAdvice();
}
}
What about minimizing the whole problem to simplest reproducible code which you can simply show here? Nobody is interested in downloading and reviewing whole your project. Moreover for later reference the related code should be still here.
I checked your just configurations of your project and your client code and I see two blocking issues:
If you want to enforce impersonation from configuration you must use only bindings with windows authentication - your endpoint exposed over HTTPS is without authentication.
Impersonation in WCF also requires client to allow service to impersonate his identity so setting the configuration on the service is not enough.
Here you have some article about impersonation and all necessary / possible settings.
I've been looking for this answer, and all I found was this link, but when I attempted to follow the tutorial I failed hard. What I need is to connect my Silverlight application to a database, just to show informations from a specific table. As I don't want to use the same ORM for my page and my silverlight app, I created a new WCF webservice project, and created my LINQ to SQL classes inside of it.
I tested my WCF service and it works fine, but somehow my Silverlight App doesnt reach it. I've changed the web.config file, and now it looks as follows.
My web.config
<?xml version="1.0"?> <configuration>
<connectionStrings>
<add name="bd_webportosConnectionString" connectionString="Data Source=BARNEY\DEV;Initial Catalog=bd_webportos;User ID=sa;Password=Stigeo_1_adm_1"
providerName="System.Data.SqlClient" /> </connectionStrings> <system.web>
<compilation debug="true" targetFramework="4.0" /> </system.web> <system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="basicHttpBindingConfig">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Ntlm"/>
</security>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:7298/DataToSilverlight.svc"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
contract="DataRetrieverReference.IService1" name="BasicHttpBinding_IService1" />
</client>
<behaviors>
<serviceBehaviors>
<behavior>
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
<serviceMetadata httpGetEnabled="true"/>
<!-- To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information
-->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" /> </system.serviceModel> <system.webServer>
<modules runAllManagedModulesForAllRequests="true"/> </system.webServer> </configuration>
I don't know how to solve this problem. And although I got stuck, I tried to keep going forward, but then I got stuck again in the next step, that was to add the service reference to my silverlight app. As I try to do what it says, the following message is shown:
There was an error downloading
metadata from the address. Please
verify that you have entered a valid
address.
I tested the service through WCF Test Client, and it worked, but my silverlight app doesn't reach it. I get the following exception:
An error occurred while trying to make
a request to URI
'http://localhost:7298/DataToSilverlight.svc'.
This could be due to attempting to
access a service in a cross-domain way
without a proper cross-domain policy
in place, or a policy that is
unsuitable for SOAP services. You may
need to contact the owner of the
service to publish a cross-domain
policy file and to ensure it allows
SOAP-related HTTP headers to be sent.
This error may also be caused by using
internal types in the web service
proxy without using the
InternalsVisibleToAttribute attribute.
Please see the inner exception for
more details.
Can you guys help me solving this big problem, or even showing another way to achieve what I want?
I also recently discovered that my crossdomain.xml doesn't get loaded ... but I don't know what that means.
Silverlight runs in very sandboxed environment. So when ever we want make a call to the WCF service from silverlight app, then we have to deploy simple policy.xml and crossdomain.xml in root director and application director of IIS. if you running an silverlight app from VS studio webserver and WCF is hosted in VS internal web server, then you will not experience such problem.
According to MSDN the <services> tag should be inside your <system.serviceModel> tag. Just copy the whole block in there.
Edit: About the connect to database part.
Silverlight can not magically "query" the database through the WCF service unless you create a WCF Data Service/OData. To get data from the database to your Silverlight client in a straight forward way you need to create methods in the WCF service that queries the database according to the in-parameters of the WCF method, packs it up i a suitable data structure (List<Customer> in the example in you link) and returns the result to the Silverlight client.
The error you get "There was an error downloading metadata from the address. Please verify that you have entered a valid address." is not an error relevant to the database, it is an error telling that your WCF service can not be found. That would have happened regardless if your WCF service used a database or not.
It looks like there might be further configuration errors in the WCF service, that might explain why the reference to the service can not be added. How does your dialog corresponding to "Figure 3-13. Adding a reference to the Web Service" look like? You can edit your question and insert a screen dump.
You can try this way :
http://www.dotnetspider.com/tutorials/Silverlight-Tutorial-315.aspx
Simple and easy.