How to configure client to catch local WCF requests in Fiddler? - c#

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.

Related

WCF service works locally on App Server but can reach it from Web Server

I have WCF service works locally on App Server http://appserver.org/UserManagementService.svc?wsdl and https://localhost/UserManagementService.svc meaning that it will show me the XML defenition of the WSDL, but can NOT reach http://appserver.org/UserManagementService.svc?wsdl or http://appserver.org/UserManagementService.svc from Web Server, I also cant reach those address's from my development machine, inside VS or directly in a browser. I get the error below when I try:
There was an error downloading 'https://appserver.org/UserManagementService.svc/_vti_bin/ListData.svc/$metadata'.
The request failed with HTTP status 404: Not Found.
Metadata contains a reference that cannot be resolved: 'https://appserver.org/UserManagementService.svc'.
There was no endpoint listening at https://prod-uibenapps.sces.org/UserManagementService.svc that could accept the message. This is often caused by an incorrect address or SOAP action. See InnerException, if present, for more details.
The remote server returned an error: (404) Not Found.
If the service is defined in the current solution, try building the solution and adding the service reference again.
This is the web.config for the service application hosting the services in IIS
<system.serviceModel>
<services>
<service name="WedWiaPortal.SCAL">
<host>
<baseAddresses>
<!--<add baseAddress="http://localhost/usermanagementservice"/>-->
<add baseAddress="http://prod-uibenapps.sces.org/UserManagementService.svc"></add>
</baseAddresses>
</host>
<endpoint address=""
binding="wsHttpBinding"
contract="WedWiaPortal.SCAL.IUserManagementService" />
<endpoint address="mex"
binding="mexHttpBinding"
contract="IMetadataExchange" />
</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>
Thank you in advance for any help, have been banging my head a couple of days.

Failed to invoke the service. Possible causes: The service is offline or inaccessible while Invoking

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>

500 Internal Server error while accessing WCF service from http and unable to add service reference for the same reason

I am trying to access my WCF service that resides on a sub-domain on my website. The properties of server on which sub-domain is situated is as follows:
It has basic authentication
It has 4.0 .NET version
But the problem is, when I try to access the service like http://mysubdomain.mydomain.com/Service1.svc it gives me
500 - Internal server error.
Although it is working fine from localhost. I also changed the properties in the web.config as:
<services>
<service behaviorConfiguration="WCFService.Service1Behavior"
name="WCFService.WrangleCore">
<endpoint address="http://mysubdomain.mydomain.com/ServiceCore.svc" binding="basicHttpBinding" contract="WCFService.IService1">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="WCFService.Service1Behavior">
<!-- 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>
</system.serviceModel>
Please tell me the solution to this.
It is worth checking if your DNS suffixes are correctly configured. I have seen it to due to a silly spelling mistake as well!

WCF Windows Service consuming Service embedded in Windows Form

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.

WCF, changing the baseAdress of an endpoint

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).

Categories