For testing I have a little selfhosted webservice that returns the length of a submitted string.
It works fine with strings shorter or equal 32767 but loger strings are cut off.
I am testing with WCFtestclient and also adjusted the buffers in the client config.But it seems to be ignored. Found a lot of samples with IIS hosted services that just increase the buffers and it seems to work. in selfhosting it seems that it does not.
This is my app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="NewBinding0" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647" transferMode="Buffered"
messageEncoding="Text">
<readerQuotas maxDepth="2147483647"
maxStringContentLength="2147483647"
maxArrayLength="2147483647"
maxBytesPerRead="2147483647"
maxNameTableCharCount="2147483647"/>
</binding>
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://CELSIUS:8080/RWService/RWService.svc"
binding="basicHttpBinding" bindingConfiguration="NewBinding0"
contract="RWOrderServiceWCF.IRWWCFService" name="testclient"
kind="" endpointConfiguration="">
<identity>
<certificateReference storeName="My" storeLocation="LocalMachine"
x509FindType="FindBySubjectDistinguishedName" />
</identity>
</endpoint>
</client>
<behaviors>
<serviceBehaviors>
<behavior name="NewBehavior0">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<services>
<service behaviorConfiguration="NewBehavior0" name="RWOrderServiceWCF.RWWCFService">
<endpoint address="RWService.svc" binding="basicHttpContextBinding"
bindingConfiguration="" contract="RWOrderServiceWCF.IRWWCFService"
isSystemEndpoint="false" />
<host>
<baseAddresses>
<add baseAddress="http://CELSIUS:8080/RWService" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
Related
I have a custom tcp binding I want to test on a service, specifically to disable the security:
<bindings>
<netTcpBinding>
<binding name="customTcpBinding" maxReceivedMessageSize="20480000" transferMode="Streamed" >
<security mode="None"></security>
</binding>
</netTcpBinding>
</bindings>
However, upon using the tcp binding's name in the config I recieve this error:
Severity Code Description Project File Line
Warning The 'binding' attribute is invalid - The value 'customTcpBinding' is invalid according to its datatype 'serviceBindingType' - The Enumeration constraint failed. Server C:\Users\Totally Not Beau\documents\visual studio 2015\Projects\WCF Proj\WCF Proj\App.config 24
Endpoint config:
<endpoint
address=""
binding="customTcpBinding"
bindingConfiguration=""
contract="Server.IMyService">
</endpoint>
Whole file if it helps:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netTcpBinding>
<binding name="customTcpBinding" maxReceivedMessageSize="20480000" transferMode="Streamed" >
<security mode="None"></security>
</binding>
</netTcpBinding>
</bindings>
<services>
<service name="Server.MyService">
<endpoint address="" binding="customTcpBinding" bindingConfiguration=""
contract="Server.IMyService">
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://192.168.2.7:8732/MyService/" />
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
</configuration>
Any advice would be greatly appreciated!
I think what you want is
<endpoint
address=""
binding="netTcpBinding"
bindingConfiguration="customTcpBinding"
contract="Server.IMyService">
</endpoint>
You may have to specify an actual address too, I'm not positive.
I new to wcf however i'm attempting to use net.tcp binding wcf service to transmit an xml file to the client.
I can get up to creating the xml file and upon attempting to connect to my wcf service fails.
I followed this guide http://msdn.microsoft.com/en-us/library/ff647180.aspx up to creating the windows test app, i'm using a web project for this.
I have added the service reference to project and below is the code i'm attempting to execute:
public string SendXMLDocument(XmlDocument xDoc)
{
var message = Message.CreateMessage(MessageVersion.Soap11, "Request_for_action", new XmlNodeReader(xDoc));
var factory = new ChannelFactory<IActionServiceLibrary>("IMMS.ActionsServiceLibrary.IActionServiceLibrary");
var channel = factory.CreateChannel();
var response = channel.Request(message);
channel.Close();
return response.ToString(); //this should come back okay..
}
my library appconfig looks like:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<client>
<endpoint address="net.tcp://localhost:8080/ActionService/" binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IActionServiceLibrary" contract="IMMS.ActionsServiceLibrary.IActionServiceLibrary"
name="IMMS.ActionsServiceLibrary.IActionServiceLibrary">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
<services>
<service name="IMMS.ActionsServiceLibrary.ActionServiceLibrary">
<endpoint address="net.tcp://localhost:8080/ActionService/" binding="netTcpBinding" bindingConfiguration=""
contract="IMMS.ActionsServiceLibrary.IActionServiceLibrary">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8080/ActionService/" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="Action_Service" sendTimeout="00:01:00" transactionFlow="false"
listenBacklog="2147483647" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647" portSharingEnabled="false">
<reliableSession enabled="false" />
<security mode="None">
<transport clientCredentialType="None" protectionLevel="None" />
<message clientCredentialType="None" />
</security>
</binding>
<binding name="NetTcpBinding_IActionServiceLibrary" />
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
the app config for the service:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="aspnet:UseTaskFriendlySynchronizationContext" value="true" />
</appSettings>
<system.web>
<compilation debug="true" />
</system.web>
<!-- When deploying the service library project, the content of the config file must be added to the host's
app.config file. System.Configuration does not support config files for libraries. -->
<system.serviceModel>
<client>
<endpoint address="net.tcp://localhost:8080/ActionService/" binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IActionServiceLibrary" contract="IMMS.ActionsServiceLibrary.IActionServiceLibrary"
name="IMMS.ActionsServiceLibrary.IActionServiceLibrary">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
<services>
<service name="IMMS.ActionsServiceLibrary.ActionServiceLibrary">
<endpoint address="net.tcp://localhost:8080/ActionService/" binding="netTcpBinding" bindingConfiguration=""
contract="IMMS.ActionsServiceLibrary.IActionServiceLibrary">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexTcpBinding" bindingConfiguration=""
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:8080/ActionService/" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="Action_Service" sendTimeout="00:01:00" transactionFlow="false"
listenBacklog="2147483647" maxBufferPoolSize="2147483647" maxBufferSize="2147483647"
maxReceivedMessageSize="2147483647" portSharingEnabled="false">
<reliableSession enabled="false" />
<security mode="None">
<transport clientCredentialType="None" protectionLevel="None" />
<message clientCredentialType="None" />
</security>
</binding>
<binding name="NetTcpBinding_IActionServiceLibrary" />
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="">
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="false" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
i get a name mismatch on the channel creation.
any help to point me in the right direction for transmitting a xml file through wcf would be great.
I found out that my config file was messed up after fixing the errors it works now.
I was digging a lot in stackoverflow.com to find answer for error: "HTTP request was forbidden by the client authentication scheme 'Anonymous", but none of proposed solutions solves my problem. So I decided to show my config files and ask about help.
I have WCF web service secured with SSL. All is fine until I started editin my WinForms Client which throws all the time error: "HTTP request was forbidden by the client authentication scheme 'Anonymous".
This is my WCF web service configuration file:
<?xml version="1.0" encoding="utf-8"?>
<bindings>
<wsHttpBinding>
<binding name="MBServiceBinding" closeTimeout="00:05:00" openTimeout="00:05:00"
receiveTimeout="00:05:00" sendTimeout="00:05:00" bypassProxyOnLocal="false"
hostNameComparisonMode="StrongWildcard" maxBufferPoolSize="2147483647"
maxReceivedMessageSize="2147483647" messageEncoding="Text" textEncoding="utf-8"
useDefaultWebProxy="true" allowCookies="false">
<readerQuotas maxDepth="2147483647" maxStringContentLength="2147483647"
maxArrayLength="2147483647" maxBytesPerRead="2147483647" maxNameTableCharCount="2147483647" />
<security mode="TransportWithMessageCredential">
<transport clientCredentialType="None" />
<message clientCredentialType="UserName" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehaviors">
<serviceMetadata httpGetEnabled="true" httpsGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="false" />
<serviceCredentials>
<userNameAuthentication userNamePasswordValidationMode="Custom" customUserNamePasswordValidatorType="SkillsAndTasks.CustomValidator, SkillsAndTasks"/>
</serviceCredentials>
</behavior>
</serviceBehaviors>
</behaviors>
<protocolMapping>
<add binding="wsHttpBinding" scheme="https" bindingConfiguration="MBServiceBinding" />
</protocolMapping>
<services>
<service behaviorConfiguration="ServiceBehaviors" name="SkillsAndTasks.MBService">
<endpoint binding="wsHttpBinding" contract="SkillsAndTasks.IMBService" />
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange" />
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="false" multipleSiteBindingsEnabled="true" minFreeMemoryPercentageToActivateService="0" />
And this is my WinForms App.config file:
<?xml version="1.0" encoding="utf-8" ?>
<applicationSettings>
<SkillsAndTasksDesktopClient.Properties.Settings>
<setting name="MBService" serializeAs="String">
<value>https://127.0.0.1/MBService.svc</value>
</setting>
<setting name="MBServiceLogin" serializeAs="String">
<value>ws1349</value>
</setting>
<setting name="MBServicePassword" serializeAs="String">
<value>qqlka123</value>
</setting>
</SkillsAndTasksDesktopClient.Properties.Settings>
</applicationSettings>
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSHttpBinding_IMBService" />
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://127.0.0.1/MBService.svc" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IMBService" contract="MBService.IMBService"
name="WSHttpBinding_IMBService">
</endpoint>
<endpoint address="mex" binding="mexHttpsBinding" contract="IMetadataExchange"/>
</client>
</system.serviceModel>
Certainly I can preview web service in browser. I have binded my site with self-signed certificate (https) too.
I suspect that it must be something with security settings...
I am using WCF and found this error:
" The caller was not authenticated by the service."
I have used this code in client.config file:
<system.serviceModel>
<bindings>
<wsHttpBinding>
<binding name="WSDualHttpBinding_IReceiverController" closeTimeout="00:00:05"
openTimeout="00:00:05" receiveTimeout="00:10:00" sendTimeout="00:00:05"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536"
messageEncoding="Text" textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" />
<security mode="None">
<message clientCredentialType="Windows" negotiateServiceCredential="false" />
</security>
</binding>
<binding name="WSHttpBinding_IEMRProWCFService" />
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://pionbuggs-pc:4567/EMRProWCFService.svc"
binding="wsHttpBinding" bindingConfiguration="WSHttpBinding_IEMRProWCFService"
contract="EMRProWCFService.IEMRProWCFService" name="WSHttpBinding_IEMRProWCFService">
<identity>
<dns value="http://pionbuggs-pc:4567/EMRProWCFService.svc" />
</identity>
</endpoint>
</client>
</system.serviceModel>
And below is the code in the service.config file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.web>
<compilation />
<httpRuntime maxRequestLength="2147483647" />
</system.web>
<system.serviceModel>
<services>
<service name="WCFService.EMRProWCFService">
<endpoint address="" binding="wsHttpBinding" contract="WCFService.IEMRProWCFService">
<identity>
<dns value="http://pionbuggs-pc:4567/EMRProWCFService.svc" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<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="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
<bindings>
<webHttpBinding>
<binding name="WebConfiguration" maxBufferSize="65536" maxReceivedMessageSize="2147483647" transferMode="Streamed">
</binding>
</webHttpBinding>
</bindings>
</system.serviceModel>
<system.webServer>
<modules runAllManagedModulesForAllRequests="true" />
<directoryBrowse enabled="true" />
</system.webServer>
</configuration>
Instead of using binding="wsHttpBinding", try using just a basic, changing you client endopint to:
<endpoint address="http://pionbuggs-pc:4567/EMRProWCFService.svc"
binding="basicHttpBinding" bindingConfiguration="WSHttpBinding_IEMRProWCFService"
contract="EMRProWCFService.IEMRProWCFService" name="WSHttpBinding_IEMRProWCFService">
and on your service to:
<endpoint address="" binding="basicHttpBinding" contract="WCFService.IEMRProWCFService">
The error is that you use advanced security that requires you to use authentication, unless there are security constrains that require it.
Here's some info about it:
BasicHttpBinding vs WsHttpBinding vs WebHttpBinding
I have a Windows Service that hosts a WCF Service. I also have a client that connects to it and messages are sent back and forth. When I send a message from the client to the service the client catches the following excption:
The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.
This is a little odd because I am not expecting the service to reply directly to the message sent by the client. The service gets the message successfully, but then the client throws this exception and seems to lose its connection to the service.
Here is the Service app.config. Disregard the bit about RESTfull service:
<?xml version="1.0"?>
<configuration>
<system.serviceModel>
<services>
<service name="OSAERest.api" behaviorConfiguration="MyServiceBehavior">
<endpoint address="http://localhost:8732/api"
binding="webHttpBinding"
contract="OSAERest.IRestService"
behaviorConfiguration="WebHttp"/>
</service>
<service name="WCF.WCFService" behaviorConfiguration="WCFBehavior">
<endpoint address="" binding="wsDualHttpBinding" bindingConfiguration="WCFBinding" contract="WCF.IWCFService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint
address="mex"
binding="mexHttpBinding"
bindingConfiguration=""
contract="IMetadataExchange"/>
<host>
<baseAddresses>
<add baseAddress="http://localhost:8731/Design_Time_Addresses/WCF/WCFService/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
<behavior name="WCFBehavior">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
<dataContractSerializer maxItemsInObjectGraph="2147483647" />
<serviceTimeouts transactionTimeout="05:05:00" />
<serviceThrottling maxConcurrentCalls="500" maxConcurrentSessions="500"
maxConcurrentInstances="2147483647" />
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="WebHttp">
<webHttp />
</behavior>
</endpointBehaviors>
</behaviors>
<bindings>
<wsDualHttpBinding>
<binding name="WCFBinding">
<security mode="None">
</security>
</binding>
</wsDualHttpBinding>
</bindings>
</system.serviceModel>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="lib" />
</assemblyBinding>
</runtime>
</configuration>
And here is the client app.config:
<?xml version="1.0"?>
<configuration>
<appSettings>
<add key="ServiceIP" value="127.0.0.1"/>
</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="lib" />
</assemblyBinding>
</runtime>
<system.serviceModel>
<bindings>
<wsDualHttpBinding>
<binding name="WSDualHttpBinding_IWCFService" closeTimeout="00:01:00"
clientBaseAddress="http://localhost:8733/Design_Time_Addresses/WCF/WCFService/"
openTimeout="00:00:10" receiveTimeout="00:10:00" sendTimeout="00:00:10"
bypassProxyOnLocal="false" transactionFlow="false" hostNameComparisonMode="StrongWildcard"
maxBufferPoolSize="524288" maxReceivedMessageSize="65536" messageEncoding="Text"
textEncoding="utf-8" useDefaultWebProxy="true">
<readerQuotas maxDepth="32" maxStringContentLength="8192" maxArrayLength="16384"
maxBytesPerRead="4096" maxNameTableCharCount="16384" />
<reliableSession ordered="true" inactivityTimeout="00:10:00" />
<security mode="None">
<message clientCredentialType="Windows" negotiateServiceCredential="true" />
</security>
</binding>
</wsDualHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8731/Design_Time_Addresses/WCF/WCFService/"
binding="wsDualHttpBinding" bindingConfiguration="WSDualHttpBinding_IWCFService"
contract="WCFService.IWCFService" name="WSDualHttpBinding_IWCFService">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
</system.serviceModel>
</configuration>
Why is the client catching this exception?
EDIT:
Here is the C# code where I am sending the message to the service if that helps:
WCFServiceClient wcfObj;
EndpointAddress ep = new EndpointAddress("http://localhost:8731/Design_Time_Addresses/WCF/WCFService/");
InstanceContext context = new InstanceContext(this);
wcfObj = new Manager_WPF.WCFService.WCFServiceClient(context, "WSDualHttpBinding_IWCFService", ep);
wcfObj.Subscribe();
wcfObj.messageHost(message);
I've had the same problem with silverlight client and duplex tcp binding. The probem was caused by invoking callback to client right before returning from wcf method call. I've fixed this by putting callback invoke into background thread:
...
ThreadPool.QueueUserWorkItem(state =>
{
//this notifies service subscribers (calls registered callbacks)
OnConfigurationUpdated(EventArgs.Empty);
});
return;