WCF service exposing multiple endpoints giving error 400/415 - c#

We have a WCF SOAP service hostied in IIS, that is used to upload binary data. To allow larger payloads (avoiding base64-encoded binary data) we want to add an endpoint that accepts MTOM messages, while retaining the current SOAP endpoint for legacy clients and backwards compatibility. Thus the desired end result is the following:
http://www.myorg.com/Service.svc gives the SOAP endpoint (currently exists and works)
http://www.myorg.com/Service.svc/mtom gives the SOAP w/MTOM endpoint (new, doesn't work)
I thought this would be as easy as adding an additional <endpoint> element with its bindingConfiguration set to point to a new <binding messageEncoding="Mtom"> element, but this doesn't work: when attempting to GET http://www.myorg.com/Service.svc/mtom the server always returns error 400 with an empty response body. When attempting to POST to the same endpoint (via the WCF Test Client) an error 415 is returned:
Cannot process the message because the content type 'application/soap+xml; charset=utf-8' was not the expected type 'text/xml; charset=utf-8'."
My config:
<behaviors>
<serviceBehaviors>
<behavior name="Service">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="true" />
<useRequestHeadersForMetadataAddress>
<defaultPorts>
<add scheme="http" port="80" />
<add scheme="https" port="443" />
</defaultPorts>
</useRequestHeadersForMetadataAddress>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<basicHttpBinding>
<binding name="ServiceMTOM" messageEncoding="Mtom" maxReceivedMessageSize="2147483647">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="16384" />
</binding>
<binding name="Service" maxReceivedMessageSize="2147483647">
<security mode="Transport">
<transport clientCredentialType="None" />
</security>
<readerQuotas maxDepth="32" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="16384" />
</binding>
</basicHttpBinding>
</bindings>
<services>
<service name="Service" behaviorConfiguration="Service">
<endpoint address="" binding="basicHttpBinding" contract="MyNamespace.Service" bindingConfiguration="Service" />
<endpoint address="mtom" binding="basicHttpBinding" contract="MyNamespace.Service" bindingConfiguration="ServiceMTOM" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
It's been a long time since I've had to work with WCF - what am I missing?

Related

Service running on another Service throw AggregateException in staging server (not in production)

We have a service
RENEWAL (service run in cl-app1) using a service "UQPDF" (using https://abc/Html2Pdf.svc in server cl-web1)
when I try to publish RENEWAL with same content but a staging version of
it in cl-app2 using a staging service "UQPDF" (using https://abc-staging/Html2Pdf.svc in server cl-web2)
there is no error for production which is the one in cl-app1 and call cl-web1 pdf service,
and no problem running locally for staging RENEWAL.
the only problem is when I publish it in app2 using https://abc-staging/Html2Pdf.svc.
it throws the following exception
System.AggregateException: One or more errors occurred. ---> System.InvalidOperationException: Could not find default endpoint element that references contract 'EmailToPdf_Staging.IHtml2PdfService' in the ServiceModel client configuration section. This might be because no configuration file was found for your application, or because no endpoint element matching this contract could be found in the client element.
AppConfig of Renewal
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IHtml2PdfService" maxBufferPoolSize="20000000"
maxReceivedMessageSize="20000000" allowCookies="true">
<readerQuotas maxDepth="32" maxStringContentLength="200000000"
maxArrayLength="200000000" />
<security mode="Transport">
<transport clientCredentialType="None" />
<message clientCredentialType="None" negotiateServiceCredential="false"
establishSecurityContext="false" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="https://abc/Html2Pdf.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IHtml2PdfService"
contract="EmailToPdf.IHtml2PdfService" name="WSHttpBinding_IHtml2PdfService" />
<endpoint address="https://abc-staging/Html2Pdf.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IHtml2PdfService"
contract="EmailToPdf_Staging.IHtml2PdfService" name="WSHttpBinding_IHtml2PdfService" />
</client>
</system.serviceModel>
UQPDF Webconfig
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IHtml2PdfService" closeTimeout="00:01:00" openTimeout="00:01:00"
receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false"
hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="6553600"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="65536000" maxArrayLength="65536000" maxBytesPerRead="4096"
maxNameTableCharCount="1638400" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
<security mode="Transport">
<transport clientCredentialType="None" />
<message clientCredentialType="None"
negotiateServiceCredential="false"
establishSecurityContext="false" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<services>
<service name="Ubiquity.uSuite3.PdfServices.Html2PdfService" behaviorConfiguration="uqpdf.ServiceBehavior">
<!-- Service Endpoints -->
<endpoint address="" binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IHtml2PdfService"
contract="Ubiquity.uSuite3.PdfServices.IHtml2PdfService" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="uqpdf.ServiceBehavior">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
I suspect that your client did not find your contract through your configuration file.You can refer to my configuration.
Here is my demo:
<client>
<endpoint address="http://localhost:8012/ServiceModelSamples/service"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
contract="Client4.IService1" name="BasicHttpBinding_Client4" />
<endpoint address="http://localhost:8012/ServiceModelSamples/service"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IService1"
contract="Client2.IService1" name="BasicHttpBinding_Client2" />
</client>
This is the configuration file of the endpoint,I suggest you do not set their names to the same.
ChannelFactory<Client4.IService1> Client4 = new ChannelFactory<Client4.IService1>("BasicHttpBinding_Client4");
Client4.IService1 chanel4 = Client4.CreateChannel();
ChannelFactory<Client2.IService1> Client2 = new ChannelFactory<Client2.IService1>("BasicHttpBinding_Client2");
Client2.IService1 chanel2 = Client2.CreateChannel();
We create different channels according to different endpoints to call services.

Https and Could not find a base address that matches scheme https for the endpoint with binding WSHttpBinding

I have a WCF Service hosting in web site IIS, in Windows Server 2012.
Site Bindings has only
https myhostname.labsoa 443
I call URL in IExplorer https://myhostname.labsoa/RoutingService.svc
I want ONLY call to Wcf Service using https
Note: replace real value by myhostname.labsoa
I get the message error:
Could not find a base address that matches scheme http for the
endpoint with binding WSHttpBinding. Registered base address schemes
are [https]
In my WCF Service host, I have this configuration files:
web.config
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5"/>
<customErrors mode="Off"></customErrors>
</system.web>
<system.serviceModel>
<bindings configSource="Config\system.serviceModel.bindings.config"/>
<services configSource="Config\system.serviceModel.services.config"/>
<behaviors configSource="Config\system.serviceModel.behaviors.config"/>
<client configSource="Config\system.serviceModel.client.config"/>
<routing configSource="Config\system.serviceModel.routing.config"/>
<protocolMapping>
<add binding="basicHttpsBinding" scheme="https" />
</protocolMapping>
<serviceHostingEnvironment
aspNetCompatibilityEnabled="false"
multipleSiteBindingsEnabled="true" />
</system.serviceModel>
Config\system.serviceModel.behaviors.config
<behaviors>
<serviceBehaviors>
<behavior name="routingData">
<serviceMetadata httpGetEnabled="True"
httpsGetEnabled="true" />
<routing filterTableName="routingTable1" routeOnHeadersOnly="false" />
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
Config\system.serviceModel.bindings.config
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_Default" closeTimeout="00:05:00"
openTimeout="00:05:00" receiveTimeout="00:10:00" sendTimeout="00:05:00"
allowCookies="false" bypassProxyOnLocal="false" hostNameComparisonMode="StrongWildcard"
maxBufferSize="2147483647" maxBufferPoolSize="2147483647" maxReceivedMessageSize="2147483647"
messageEncoding="Text" textEncoding="utf-8" transferMode="Buffered"
useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
<message clientCredentialType="UserName" algorithmSuite="Default" />
</security>
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="wsHttpBinding_Default" maxReceivedMessageSize="2147483647">
<security mode="Transport">
<transport clientCredentialType="None" proxyCredentialType="None" realm="" />
</security>
</binding>
</wsHttpBinding>
</bindings>
Config\system.serviceModel.services.config
<services>
<service behaviorConfiguration="routingData"
name="System.ServiceModel.Routing.RoutingService">
<host>
<baseAddresses>
<add baseAddress="https://myhostname.labsoa/RoutingService.svc"/>
</baseAddresses>
</host>
<endpoint address=""
binding="wsHttpBinding"
name="reqReplyEndpoint"
contract="System.ServiceModel.Routing.IRequestReplyRouter" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
<endpoint
address="/Contacto"
binding="wsHttpBinding"
contract="System.ServiceModel.Routing.IRequestReplyRouter"
name="ContactoRouting"
bindingConfiguration="wsHttpBinding_Default"
/>
Any suggestions about it?
Your endpoing configuration doesnt have bindinginConfiguration.
Following configuration
<endpoint address=""
binding="wsHttpBinding"
name="reqReplyEndpoint"
contract="System.ServiceModel.Routing.IRequestReplyRouter" />
should be
<endpoint address=""
binding="wsHttpBinding"
name="reqReplyEndpoint"
bindingConfiguration="wsHttpBinding_Default"
contract="System.ServiceModel.Routing.IRequestReplyRouter" />

WCF Error - 'Maximum number of items that can be serialized or deserialized in an object graph is '65536'

I have facing above error after adding the maxItemsInObjectGraph="2147483647" parameter both server and client.
However in my project large number of data can transferred using "datatable" objects without any issue.
This error occurred large number of data transferred with using "List<>" objects.
My dotnetframework is 4.0, but I found this error NOT found in dotnetframework 4.5 and large number of data can transferring using "List<>" object without error. Also this is Windows base project.
Please anyone can solved this problem. Here are the my server and client app.cofig configurations.
Thanks!!!
My Service;
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="CommonBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
<serviceMetadata httpGetEnabled="false"/>
<serviceDebug includeExceptionDetailInFaults="true" />
<serviceThrottling
maxConcurrentSessions="1200"
maxConcurrentCalls="192"
maxConcurrentInstances="1392"
/>
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding maxReceivedMessageSize="2147483647" name="netTcpBinding" transferMode="Streamed" listenBacklog="2000" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="2000"
closeTimeout="08:00:00" openTimeout="08:00:00" receiveTimeout="08:00:00" sendTimeout="08:00:00">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="08:00:00"
enabled="false" />
<security mode="None">
<transport clientCredentialType ="None"/>
</security>
</binding>
</netTcpBinding>
</bindings>
<services>
<service behaviorConfiguration="CommonBehavior" name="MyBLL">
<endpoint address="" binding="netTcpBinding" bindingConfiguration="netTcpBinding" name="MyEndPoint" contract="IMy">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8000/MySVC"/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
My Client;
<system.serviceModel>
<client>
<endpoint name="MyEndPoint" address="net.tcp://localhost:8000/MySVC" binding="netTcpBinding" bindingConfiguration="netTcpBinding" contract="IMy" />
</client>
<behaviors>
<endpointBehaviors>
<behavior name="CommonBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="netTcpBinding" maxReceivedMessageSize="2147483647" transferMode="Streamed" listenBacklog="2000" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="2000"
closeTimeout="08:00:00" openTimeout="08:00:00" receiveTimeout="08:00:00" sendTimeout="08:00:00">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="08:00:00"
enabled="false" />
<security mode="None">
<transport clientCredentialType ="None"/>
</security>
</binding>
</netTcpBinding>
</bindings>
<services>
<service behaviorConfiguration="CommonBehavior" name="MyEndPoint">
<endpoint address="" behaviorConfiguration="CommonBehavior" binding="netTcpBinding" bindingConfiguration="netTcpBinding" name="MyEndPoint" contract="Imy">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8000/MySVC" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
Finally I found my mistake in client config and I was solved my problem.
My mistake was behaviorConfiguration="CommonBehavior" tag not in the client, endpoint section. After added this part the problem was successfully solved and large number of records exist generic list I can transferred from server to client.
This is my corrected client config -
<system.serviceModel>
<client>
<endpoint name="MyEndPoint" behaviorConfiguration="CommonBehavior" address="net.tcp://localhost:8000/MySVC" binding="netTcpBinding" bindingConfiguration="netTcpBinding" contract="IMy" />
</client>
<behaviors>
<endpointBehaviors>
<behavior name="CommonBehavior">
<dataContractSerializer maxItemsInObjectGraph="2147483647"/>
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="netTcpBinding" maxReceivedMessageSize="2147483647" transferMode="Streamed" listenBacklog="2000" maxBufferPoolSize="2147483647" maxBufferSize="2147483647" maxConnections="2000"
closeTimeout="08:00:00" openTimeout="08:00:00" receiveTimeout="08:00:00" sendTimeout="08:00:00">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647" maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<reliableSession ordered="true" inactivityTimeout="08:00:00"
enabled="false" />
<security mode="None">
<transport clientCredentialType ="None"/>
</security>
</binding>
</netTcpBinding>
</bindings>
</system.serviceModel>

WCF - There was no endpoint listening at http://xxxxx.xxxx/Service1.svc

When trying to call a function on the WCF Service i getting the error:
There was no endpoint listening at http://XXXXXXXXXXX.xxx/Service1.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
My WCF Service Web.config
<system.serviceModel>
<services>
<service name="Service1" behaviorConfiguration="MyServiceTypeBehaviors">
<endpoint contract="IService1" binding="mexHttpBinding" address="mex" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
</system.serviceModel>
WCF Client app.config
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="MetadataExchangeHttpBinding_IService1" closeTimeout="00:01:00" openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00" bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384" maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" enabled="false" />
<security mode="None">
<transport clientCredentialType="Windows" proxyCredentialType="None" realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://XXXXXXXXXXX.xxx/Service1.svc"
binding="wsHttpBinding" bindingConfiguration="MetadataExchangeHttpBinding_IService1"
contract="API.IService1" name="MetadataExchangeHttpBinding_IService1" />
</client>
</system.serviceModel>
I have tried many many settings and configurations but dont getting this to work... do anyone find anything you think i missed?
Edit: I am hosting the service on a IIS and using a Winform client
You seem to have confused with service endpoint and mex endpoint. They are separate endpoints.
Change your config on server to this:
<endpoint contract="IService1" binding="wsHttpBinding" address="" />
<endpoint contract="IMetadataExchange" binding="mexHttpBinding" address="mex" />
Then recreate proxy.

WCF Client Security defaulting to Windows

I am trying to setup a simple WCF web service with wsHTTPBinding and using a custom Username.
I have the service on a remote server setup with a self signed cert on a different port.
eg: https://service.myserice.com:442/service1.svc
For some reason the client seems to default to windows security even though I hjave set it up as UserName Security.
Here is my web Service config file:
<configuration>
<system.web>
<compilation debug="true" targetFramework="4.0" />
<customErrors mode="Off"></customErrors>
</system.web>
<system.serviceModel>
<services>
<service name="AutoSenderWCF.Service1" behaviorConfiguration="Behavior1">
<host>
<baseAddresses>
<add baseAddress="https://service.autosender.com.au:442/" />
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" bindingName="TransportBinding" contract="AutoSenderWCF.IService1"></endpoint>
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</service>
</services>
<bindings>
<wsHttpBinding>
<binding name="TransportBinding">
<security mode="TransportWithMessageCredential">
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="Behavior1">
<!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above 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="true"/>
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="AutoSenderWCF.CustomValidator, AutoSenderWCF"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
and my client code (notic ethe security=windows)
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="TransportBinding_IService1" closeTimeout="00:01:00"
openTimeout="00:01:00" receiveTimeout="00:10:00" sendTimeout="00:01:00"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true"
allowCookies="false">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00"
enabled="false" />
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://service.autosender.com.au/Service1.svc"
binding="wsHttpBinding" bindingConfiguration="TransportBinding_IService1"
contract="ServiceReference1.IService1" name="TransportBinding_IService1">
<identity>
<servicePrincipalName value="host/wserver" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
It is clearly specified to use Windows in your Client config:
<security mode="Message">
<transport clientCredentialType="Windows" proxyCredentialType="None"
realm="" />
<message clientCredentialType="Windows" negotiateServiceCredential="true"
algorithmSuite="Default" />
</security>
Copy that section from Server config.
I beleive i have solved it:
this line.
<endpoint address="" binding="wsHttpBinding" bindingName="TransportBinding" contract="AutoSenderWCF.IService1"></endpoint>
it should not be bindingName it should be bindingConfiguration

Categories