I have a Windows Service with a WCF Library. On the same machine, I have a Windows Form application with a WCF Service embedded into it. My problem arises when I try to consume the service in the Form from the Windows Service.
The WCF service in the Form has a "basicHttpBinding" endpoint exposed as well as a "mexHttpBinding". I am able to test the service in the Form with the 'WCF Test Client' with no problems.
In the Windows Service, I am able to add a Service reference to the Form's service and all is well. However, when I actually run the Windows Service, and try to consume the WCF Service in the Form, I get this error:
The message with Action 'http://tempuri.org/IService1/shutMeDown'
cannot be processed at the receiver, due to a ContractFilter mismatch
at the EndpointDispatcher. This may be because of either a contract
mismatch (mismatched Actions between sender and receiver) or a
binding/security mismatch between the sender and the receiver. Check
that sender and receiver have the same contract and the same binding
(including security requirements, e.g. Message, Transport, None).
See that "IService1" in there? I'm pretty sure that's the problem. The Windows Service itself is configured to host a Service called "Service1" as you can see below in the <services> section. So it seems like I must have something wrong in my app.config.
My best guess is that I have something wrong with the way that I have my <client> setup in my app.config. It seems like, for some reason, when I am trying to consume the service in the Form, the Windows Service is using the wrong address. It's using the address of it's own service, not the address of the Form's service.
Here are the relevant parts of the app.config from my Windows Service:
<system.serviceModel>
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IFormControlService" />
</basicHttpBinding>
</bindings>
<client>
<endpoint address="http://localhost:8700/FormControlService"
binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IFormControlService"
contract="Form_ServiceReference.IFormControlService" name="BasicHttpBinding_IFormControlService" />
</client>
<services>
<service name="smMonitor_wcfServiceLibrary.Service1">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8800/smMonitorService/" />
</baseAddresses>
</host>
<endpoint address="" binding="basicHttpBinding" contract="smMonitor_wcfServiceLibrary.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior>
<serviceMetadata httpGetEnabled="True" httpsGetEnabled="True" />
<serviceDebug includeExceptionDetailInFaults="False" />
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
My setup is this. I have a Windows Service running on a machine. On the same machine I have a Widows Form. The Windows Form exposes a service that will allow the Windows Service to interact with it.
My problem was as follows. I only had the outgoing <bindings> defined. What I needed to do was to define both the incoming and outgoing bindings like this:
<bindings>
<basicHttpBinding>
<binding name="BasicHttpBinding_IService1" />
<binding name="BasicHttpBinding_IFormControlService" />
</basicHttpBinding>
</bindings>
Since the outgoing bindings were not defined, my Windows Service was looking in the <basicHttpBinding> and just using the default one.
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 created the self hosted WCF service with C# application. I want to send messages to C# application from remote php server. How can i perform this function?
<?xml versio="1.0"?>
<configuration><system.serviceModel>
<services>
<service name="MyMathServiceLib.MyMathService" behaviorConfiguration="myMathServiceBehave">
<host>
<baseAddresses>
<add baseAddress="http://localhost:9001/MyMathService"/>
<add baseAddress="net.tcp://localhost:9002/MyMathService"/>
</baseAddresses>
</host>
<endpoint address="http://localhost:9001/MyMathService" binding="basicHttpBinding" contract="MyMathServiceLib.IMyMathService"/>
<endpoint address="net.tcp://localhost:9002/MyMathService" binding="netTcpBinding" contract="MyMathServiceLib.IMyMathService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"/>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="myMathServiceBehave">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
</configuration>
This is my app.config file(ref: http://www.codeproject.com/Articles/650869/Creating-a-Self-Hosted-WCF-Service)
My aim is to send message from php server to c# application
Follow the simple steps:
In your visual studio folder, you should see WCF Client.
Add your WCF URL to this client (http://localhost:9001/MyMathService in your case). Fill example data in the request and click on "XML".
Copy the XML and put it in a variable in PHP. Instead of your dummy values you put in the previous step, put proper PHP variables.
Enable PHP CURL. POST this variable to the WCF service.
I'm trying to host on a website both the creation of a WCF service to send JSON data back to the client-side, as well as consume a different webservice used for cross application data exchange (it's a medical app, the data I need is hosted in an old ASMX webservice somewhere else)
My problem is the app is behind SSL, and basic authentication (which will go when we deploy to live), the service I'm consuming is over http and the rediculous amount of settings I need in the web.config are getting in each others way.
The web.config looks like this now
<behaviors>
<endpointBehaviors>
<behavior name="AJAXEndpoint" >
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<services>
<service name="MyNamespace.Service.ACSvc">
<endpoint
behaviorConfiguration="AJAXEndpoint"
address="" binding="wsHttpBinding" bindingConfiguration="UsernameWithTransport"
contract="MyNamespace.Service.IACSvc">
</endpoint>
</service>
</services>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true"
multipleSiteBindingsEnabled="true" />
<bindings>
<basicHttpBinding>
<binding name="wsAbbVieSoap">
<security mode="Transport" />
</binding>
</basicHttpBinding>
<wsHttpBinding>
<binding name="UsernameWithTransport">
<security mode="Transport">
<transport clientCredentialType="Basic" />
</security>
</binding>
</wsHttpBinding>
</bindings>
<client>
<endpoint address="http://somewhere.else.com/externalservice.asmx"
binding="basicHttpBinding" bindingConfiguration="wsAbbVieSoap"
contract="AbbvieService.wsAbbVieSoap" name="wsAbbVieSoap" />
</client>
Over various iterations, I've had my service working, but the external service not working or neither service working.
What I want
My service - HTTPS, Basic authentication, response in JSON
External service - HTTP, Anonymous, SOAP response
These services are not aware of each other and have nothing to do with each other. They're separate parts of the same website - one (mine) for my own clientside scripts, and the other (external) for me to call serverside for various business uses.
Any help appreciated
I have my service configured as below:
<system.serviceModel>
<services>
<service name="WcfService1.Service1" behaviorConfiguration="MyServiceTypeBehaviors">
<host>
<baseAddresses>
<add baseAddress="net.tcp://127.0.0.1:808/service" />
</baseAddresses>
</host>
<endpoint address="net.tcp://127.0.0.1:808/service/"
binding="netTcpBinding"
contract="WcfService1.IService1"/>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
</service>
</services>
<protocolMapping>
<add scheme="net.tcp" binding="netTcpBinding"/>
</protocolMapping>
<behaviors>
<serviceBehaviors>
<behavior name="MyServiceTypeBehaviors">
<serviceMetadata httpGetEnabled="true"/>
</behavior>
</serviceBehaviors>
<endpointBehaviors>
<behavior name="MyEndpointBehaviour">
<webHttp/>
</behavior>
</endpointBehaviors>
</behaviors>
<serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true" />
</system.serviceModel>
and the client as:
<system.serviceModel>
<bindings>
<netTcpBinding>
<binding name="NetTcpBinding_IService1" sendTimeout="00:05:00" />
</netTcpBinding>
</bindings>
<client>
<endpoint address="net.tcp://127.0.0.1/service/" binding="netTcpBinding"
bindingConfiguration="NetTcpBinding_IService1" contract="IService1"
name="NetTcpBinding_IService1">
<identity>
<servicePrincipalName value="host/MachineName" />
</identity>
</endpoint>
</client>
</system.serviceModel>
When using WCFTestClient or SVCutil, I am able to discover and access the servie and generate proxy or stubs.
But when I want to invoke any of the methods getting following error:
Failed to invoke the service. Possible causes: The service is offline or inaccessible; the client-side configuration does not match the proxy; the existing proxy is invalid. Refer to the stack trace for more detail. You can try to recover by starting a new proxy, restoring to default configuration, or refreshing the service.
The socket connection was aborted. This could be caused by an error processing your message or a receive timeout being exceeded by the remote host, or an underlying network resource issue. Local socket timeout was '00:04:59.9980468'.
Set the following value inside the endpoint block
<identity>
<dns value ="localhost"/>
</identity>
Maybe not the answer you are looking for, but for development on the local machine I always use an HTTP endpoint. I find Net.TCP will only play nice when it is hosted on a server in IIS.
It is easy enough to add the NET.TCP endpoints once you deploy to an IIS server. Note: that the base address no longer has any affect as that is set in IIS. To test the new endpoints it is best to start by opening the service in a browser while remoted into the server, that way you get the best error messages.
If i understand correctly you are trying to select the endpoint when creating the service reference? Thats now how it works.
If you create your service reference using 127.0.0.1/service/Service1.svc
You should see in your config file something like the following. (When I create my service endpoints I always name them with the protocol as a suffix.
<endpoint address="http://servername:8090/servername/servername.svc/Business"
binding="basicHttpBinding" bindingConfiguration="BusinessHTTP"
contract="servername.IService" name="BusinessHTTP" />
<endpoint address="net.tcp://servername:8030/Service/Service.svc/Business"
binding="netTcpBinding" bindingConfiguration="BusinessTCP"
contract="servername.IService" name="BusinessTCP" />
then in your code you can choose which endpoint to use.
Dim svc as New SeviceReferenceName.BusinessClient("BusinessTCP")"
I have faced the same issue. It was the issue of port address of EndpointAddress. In Visual studio port address of your file (e.g. Service1.svc) and port address of your wcf project must be the same which you gives into EndpointAddress. Let me describe you this solution in detail which worked for me.
There are two steps to check the port addresses.
In your WCF Project right click to your Service file (e.g. Service1.svc) -> than select View in browser now in your browser you have url like http://localhost:61122/Service1.svc so now note down your port address as a 61122
Right click your wcf project -> than select Properties -> go to the Web Tab -> Now in Servers section -> select Use Visual Studio Development Server -> select Specific Port and give the port address which we have earlier find from our Service1.svc service. That is (61122).
Earlier, I had a different port address. After specifying the port address properly, which I got from the first step, EndpointAddress 61122, my problem was solved.
I hope this might be solved your issue.
NetTcp binding is secured by default.In the security authentication process between client and service,WCF ensures that the identity of service matches the values of this element. Therefore service need to be configured with :
<identity>
<dns value ="localhost"/>
</identity>
i have a few questions about the below config file:
<system.serviceModel>
<bindings />
<services>
<service behaviorConfiguration="WcfReporting.Service1Behavior"
name="WcfReporting.Service1">
<endpoint address=""
binding="basicHttpBinding" bindingConfiguration=""
contract="WcfReporting.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:5050/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WcfReporting.Service1Behavior" >
<!-- 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>
</system.serviceModel>
Why when I hit F5 to restart the service, the service starts with this URL http://localhost:2752/ ... why not 5050 as I specified in baseAddresses.
How how can I add another endpoint. I tried with endpoint address="/Address2" binding="basicHttpBinding" contract="WcfReporting.IService1" />
should I how be able to access the service, not only with http://localhost/VirtualDir/ but also with http://localhost/VirtualDir/address2 or how does it work?
If you're hosting in Cassini from within Visual Studio 2005 or later, you can specify the port using Project/Properties/Web/Use Visual Studio Development Server/Specific Port.
By default the port will be auto-assigned - which isn't very helpful for Web Services as your clients will probably want to be using a fixed URL.
You don't need to specify <baseAddresses> in the config file when hosting in IIS or Cassini - the base URL is provided by the web server. The <baseAddresses> element is used when self-hosting.
How how can I add another endpoint. I
tried with endpoint
address="/Address2"
binding="basicHttpBinding"
contract="WcfReporting.IService1" />
The addresses you specify in this endpoint need to be local and relative - e.g. just specify
<endpoint address="Address2"
binding="basicHttpBinding"
contract="WcfReporting.IService1" />
and this will create an endpoint at the complete address of
net.tcp://localhost:5050/Address2
But as Darin has already pointed out - if you use IIS / WAS to host your service, the virtual directory where your *.svc file resides will take precedence and the base addresses specified will be ignored. In order to really use the base addresses, you'll need to self-host the service in a console app or Windows service.
Marc
If you use a web server (such as Cassini or IIS) to host your WCF service the base address will be provided from this server. Also note that you cannot use TCP bindings over HTTP. If you want to be able to set the base address property you need to host the service yourself (for example in NT service, console or windows application).