WCF Service using soap1.2 - c#

I have this WCF service that works fine using soap1. I'm trying to change it to run in soap1.2 but I have not been able.
I have try changing different things in the webconfig.
First, I change the basicHttpBinding for wsHttpBinding. I also change the protocol, remove the soap1.1 and add the soap 1.2
How I can make that my WCF web service run in soap1.2?
Some code that I try in the config file:
<webServices>
<protocols>
<add name="HttpSoap" />
<add name="HttpSoap12" />
</protocols>
</webServices>
<protocolMapping>
<remove scheme="http" />
<add scheme="http" binding="wsHttpBinding" />
</protocolMapping>

The problem was not the project. I was using Soap UI to call the service. I did know that I have to modify the Soup UI WS-Addressing setting for it to work. I set the Must understand option to true and check the add default wsa To: option. With that the service works fine using soup ui

Related

WCF REST calling another application hosted WCF service. maxReceivedMessageSize ignored for Client setting

I have a WCF REST service that is calling another self hosted WCF service on my server.
So it looks like this:
WCF Rest Service (Internet facing) -----> Application hosted WCF Service hosted on the same server (localhost on the server).
The point of this if to expose an endpoint on the REST service which accepts an image.
The REST service then calls the secondary service. When the secondary service returns to the main WCF service, it fails with the typical "MaxReceivedMessageSize (65373) exceeded". EVEN THOUGH I'm specifying (or at least I think I am) this in the app.config of the main WCF Service.
I've configured MaxReceivedMessageSize in two other areas and it works fine...EXCEPT for the Client configuration in the app.config of the REST service.
It seems that although I'm specifying this in the app.Config for calling WCF service, it's ignoring the binding. Is this something I can even do?
Here is my app.config for the main REST service:
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true"/>
</system.web>
<connectionStrings>
<add name="dbConnectStr"
connectionString="Data Source=localhost;Initial Catalog=BDATA;Integrated Security=False;User Id=removed;Password=removed" providerName="System.Data.SqlClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<system.serviceModel>
<bindings>
<webHttpBinding>
<binding name="BasicHttpBinding_IBIImageWarpService" maxReceivedMessageSize = "1000000"/>
</webHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8080/BIImageWarp" binding="webHttpBinding"
bindingConfiguration="BasicHttpBinding_IBIImageWarpService"
contract="ServiceReference1.IBIImageWarpService" name="BasicHttpBinding_IBIImageWarpService" />
</client>
</system.serviceModel>
</configuration>
Please please please...I'm at my wits end here. This is the final piece of the puzzle for a large project I've been working on.

role of service element in web.config file for a WCF

what's the exact role of service element in web.config file for a WCF? I have seen instances where WCF services work perfectly without service element.
Here's a sample config file, whose service I can call from code behind & script (same/different domain)
<?xml version="1.0"?>
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0"/>
</system.web>
<system.serviceModel>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="true"/>
<!--Calling from different domain -->
<standardEndpoints>
<webScriptEndpoint>
<standardEndpoint name="" crossDomainScriptAccessEnabled="true">
</standardEndpoint>
</webScriptEndpoint>
</standardEndpoints>
<behaviors>
<endpointBehaviors>
<behavior name="EndPointBehavior">
<enableWebScript />
</behavior>
</endpointBehaviors>
</behaviors>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true"/>
<directoryBrowse enabled="true"/>
</system.webServer>
</configuration>
Beginning with WCF 4.0, the framework introduced the concepts of default endpoints, behaviors and bindings. This was to make WCF configuration easier. In the config file you posted, there are no defined endpoints or bindings, so the service will create a default endpoint at the location of the service file (i.e., if you have the service file at C:\inetpub\wwwroot\MyService\MyService.svc and the IIS Application is named MyService, it would be http://<servername>\MyService\MyService.svc).
The out of the box default binding is basicHttpBinding for http. So this gives you a default endpoint with basicHttpBinding. You can still explicitly define endpoints and bindings, and you can define a binding and set it to be the default for all services in that config that use that binding (by omitting the name attribute), and you can also change the binding used for a given transport in <protocolMapping> section in the <system.serviceModel> section. For example, if you wanted to use wsHttpBinding for all http requests by default, you could do this:
<protocolMapping>
<add binding="wsHttpBinding" scheme="http"/>
</protocolMapping>
There's a very good article that covers this here - A Developer's Introduction to Windows Communication Foundation 4.

WCF Service no Endpoint

When I run WCF Test Client I get an error :
Error: Cannot obtain Metadata from
localhost:52875/ControllersInfo.svc If this is a Windows (R)
Communication Foundation service to which you have access, please
check that you have enabled metadata publishing at the specified
address.
Metadata
contains a reference that cannot be resolved:
localhost:52875/ControllersInfo.svc'. There was no
endpoint listening at localhost:52875/ControllersInfo.svc that
could accept the message. This is often caused by an incorrect
address or SOAP action. See InnerException, if present, for more
details.
Here is my web.config file
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
</system.web>
<system.serviceModel>
<standardEndpoints>
<webHttpEndpoint>
<standardEndpoint helpEnabled="true" automaticFormatSelectionEnabled="true" />
</webHttpEndpoint>
</standardEndpoints>
<services>
<service name="dev_FineReceiptsService.ControllersInfo">
<endpoint kind="webHttpEndpoint" contract="dev_FineReceiptsService.IControllersInfo" />
</service>
</services>
</system.serviceModel>
<connectionStrings>
<add name="FineReceiptsTestEntities" connectionString="metadata=res://*/FineTest.csdl|res://*/FineTest.ssdl|res://*/FineTest.msl;provider=System.Data.SqlClient;provider connection string="Data Source=msdev01;Initial Catalog=FineReceiptsTest;Integrated Security=True;MultipleActiveResultSets=True"" providerName="System.Data.EntityClient" />
</connectionStrings>
</configuration>
Can anyone tell me what I have done wrong ?
I tried to find similar question but none of them helped me.
Your service is REST-based service (since you specified the webHttpBinding).
However, the WCF Test Client is a SOAP-based testing tool - you can test SOAP service with this - basicHttpBinding, wsHttpBinding etc.
But you cannot use the SOAP-based WCF Test Client to test your REST-based WCF service... that won't work. Use a regular web browser, potentially combined with Fiddler or something like that to test your REST services .
Metadata endpoints expose WSDL + XSDs which describes SOAP services. There is no support for exposing metadata for REST. Since your are using webHttpEndpoint, you can not use WCFTestClient. For testing a Rest Service, RestSharp or Browser can be used.
If you need to add metadata to SOAP service with simplfied configuration you need to add this behavior:
<configuration>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>

maxReceivedMessageSize on Azure WCF service is too small

Whenever I connect my client to send data to my WCF Azure service, I get this error:
"The maximum message size quota for incoming messages (65536) has been exceeded. To
increase the quota, use the MaxReceivedMessageSize property on the appropriate binding
element."
I've read everywhere about setting this MaxReceivedMessageSize property on both the client and server config files. I have done this.
However, whenever I update the service reference in the client, it pulls the settings back to the default of 65536. (found via investigating the .svcinfo file)
This leads me to conclude the issue must be on the service side.
I've placed this in my web.config file:
<bindings>
<basicHttpBinding>
<!--The basicHttpBinding is used for clients which use the generated code to transmit data; the following settings make it possible to send larger amounts to the service-->
<binding maxReceivedMessageSize="10000000" receiveTimeout="01:00:00">
<readerQuotas maxStringContentLength="10000000" />
</binding>
</basicHttpBinding>
</bindings>
Now, many posts talk about naming the binding and setting it in the service endpoints on the server side as well. Something like this:
<services>
<service name="YourNamespace.YourServiceClass">
<endpoint name="endpoint1"
address="http://server:8888/YourService.svc"
binding="basicHttpBinding"
bindingConfiguration="lageMessageTransfer"
contract="IYourServiceContract" />
</service>
</services>
However, I don't have these service endpoints and my service works great for small sizes.
Where else would this need to be set?
EDIT:
More information, Tim seems to be on the right track with the default endpoints. I am using a default endpoint. It seems that you cannot just explicitly define a service for that default endpoint. or if you can, I must be doing it incorrectly.
However, it seems that you can modify the binding on a default endpoint as stated by Richard. This is done by simply not specifying a name for the binding. I have tried setting the values on my service to much lower values to see if something else was lowering them, but they are completely ignored. Its as if the default endpoint is simply ignoring the binding that I have created.
For my entire config file:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.diagnostics>
<trace autoflush="true" />
<sources>
<source name="System.ServiceModel" switchValue="Information, ActivityTracing" propagateActivity="true">
<listeners>
<add name="sdt" type="System.Diagnostics.XmlWriterTraceListener" initializeData="logging.e2e" />
</listeners>
</source>
</sources>
</system.diagnostics>
<system.web>
<compilation debug="true" targetFramework="4.0">
<assemblies>
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
</assemblies>
</compilation>
</system.web>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding maxReceivedMessageSize="100" maxBufferSize="100" receiveTimeout="00:11:00">
<readerQuotas maxStringContentLength="100" />
</binding>
</basicHttpBinding>
</bindings>
<protocolMapping>
<add scheme="http" binding="basicHttpBinding" />
</protocolMapping>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" aspNetCompatibilityEnabled="false" />
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
</system.webServer>
<connectionStrings><EDITEDOUT></connectionStrings>
</configuration>
Thoughts on why the new binding settings are not being picked up?
The attribute name maxReceivedMessageSize is very explicit - it all depends on who is receiving the message - if you are sending a large amount of data then it is the service, if you are getting a large amount of data back from the service then it is the client. The service and client do not need the same value for this setting (unlike many other binding settings)
Setting an unnamed binding section should work in general as, of .NET 4, it configures the binding for anyone who doesn't explicitly specify a configuration using bindingConfiguration. However, in your example above you need to set the maxBufferSize in addition to the maxReceivedMessageSize as you are buffering rather than streaming the message. The maxBufferSize and maxReceivedMessageSize must be the same
You don't have the section in the Web.config on your service side? If you're using WCF 4.0 is it possible you're using a default endpoint?
I don't know if you can specify a binding for a default endpoint, but you might want to try specifying an endpoint via the section of the Web.config and setting bindingConfiguration to the binding specified in your section.

dynamically set WCF baseAddressPrefixFilters

I have a WCF service that I am deploying in a shared hosting environment. Because of this I have to specify baseAddressPrefixFilters (see answer here for why this is necessary). Setting the base address prefix filters happens in the web.config like so...
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://example.com"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
The problem is that I have multiple environments that are configured this way with their own urls (i.e. dev, test, prod)
I tried the following with no luck...
<serviceHostingEnvironment>
<baseAddressPrefixFilters>
<add prefix="http://dev.example.com"/>
<add prefix="http://test.example.com"/>
<add prefix="http://example.com"/>
</baseAddressPrefixFilters>
</serviceHostingEnvironment>
So the question is how do I set the baseAddressPrefixFilter dynamically at runtime?
If you are running under IIS7, this is a good walk through of the problem and solution. If not, the information for the WCF side is still what you need to know to resolve your issues.
http://keithelder.net/2008/04/28/configuring-wcf-and-iis-7-with-http-bindings-and-multiple/
Have you looked at the ServiceHostFactory? We used this in our 3.0 services to work with the different host headers.
http://blogs.msdn.com/rampo/archive/2007/06/15/supporting-multiple-iis-bindings-per-site.aspx

Categories

Resources