Error when accessing net.tcp WCF operation contracts - wcf

I have simple WCF service, I sucessfully hosted it under IIS 7. I can generate client as well ( using WCFTestClient.exe util ), however when I'm trying to run Wcf methods I'm 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
What my service does is gets the input and returns string in a format "You have entered : {0}".
Here is my web.config
<system.serviceModel>
<services>
<service behaviorConfiguration="ServiceBehavior" name="II7WcfService.MyService">
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost/artur/MyService" />
</baseAddresses>
</host>
<endpoint address="net.tcp://localhost/artur/MyService"
binding="netTcpBinding"
bindingConfiguration="PortSharingBinding"
contract="II7WcfService.IMyService" />
<endpoint address="mex"
binding="mexTcpBinding"
contract="IMetadataExchange" />
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="PortSharingBinding" portSharingEnabled="true">
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="true" />
<serviceDebug includeExceptionDetailInFaults="True" />
</behavior>
</serviceBehaviors>
</behaviors>

Related

WCF internet explorer (starter)

i created a simple WCF library and hosting the service in a console application with BasicHttpBinding endpoint .
While the console host is running . I tried to open the service in IE9 /Firefox .....
http://localhost:8080/EService/basic . In IE9 it shows error, and in Firefox it doesn't show anything.
I'm running VS 2010 as Admin
Im attaching the code
https://rapidshare.com/files/3306100109/ChatSolution.rar
The problem is that you have your service endpoint defined at 2 places in your EvalServiceLibarary and your ConsoleChat app.
Remove the ServiceModel Section from the service library and just have it in your ConsoleChat Application. I did try the below config in your console app and it works:
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="Metadata">
<serviceMetadata httpGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="NoSecurityPlusRM">
<reliableSession enabled="true" />
<security mode="None" />
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="Metadata" name="EvalServiceLibrary.EvalService">
<endpoint address="basic" binding="basicHttpBinding"
contract="EvalServiceLibrary.IEvalService" />
<endpoint address="ws" binding="wsHttpBinding"
bindingConfiguration="NoSecurityPlusRM" contract="EvalServiceLibrary.IEvalService" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8080/evals"/>
</baseAddresses>
</host>
</service>
</services>
</system.serviceModel>
Now just browse to http://localhost:8080/evals from your browser and you can see the service page.

Can't host tcp based wcf service on IIS, Cannot obtain Metadata from net.tcp://localhost/TestApp2/MyService error pops up

I have a simple test purpose WCF service. I'm trying to host it under IIS 7.5 ( Windows 7 ) but no luck so far. I'm getting error
Cannot obtain Metadata from net.tcp://localhost/TestApp2/MyService
I have a web site TestApp2 under Default Web Site, I enabled tcp on Default Web Site and TestApp2. Here is my web.config file, while I realize that this error simply states that I didn't have endpoint for metadata exchange, I can't see what's the problem because I included endpoint for metadata exchange.
<system.serviceModel>
<services>
<service behaviorConfiguration="ServiceBehavior" name="MyService">
<endpoint address="net.tcp://localhost/TestApp2/MyService"
binding="netTcpBinding"
bindingConfiguration="PortSharingBinding"
contract="II7WcfService.IService1" />
<endpoint address="MEX"
binding="mexTcpBinding"
contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost/TestApp2/MyService" />
</baseAddresses>
</host>
</service>
</services>
<bindings>
<netTcpBinding>
<binding name="PortSharingBinding" portSharingEnabled="true">
<security mode="None"/>
</binding>
</netTcpBinding>
</bindings>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior">
<serviceMetadata httpGetEnabled="False" />
<serviceDebug includeExceptionDetailInFaults="false" />
</behavior>
</serviceBehaviors>
</behaviors>
Thanks.
My guess is your service isn't actually called MyService but rather it is in a namespace. This means your declared endpoints are not getting picked up, and the default ones (which doesn't include IMetadataExchange) are being used instead.
Add the name of your namespace to the attribute in the config and it should work.

WCF - Can't Generate Metadata/Implement MEX for NetMsmq Binding under IIS WAS?

I have been successfull in implementing NetTcp bindings and metadata under WAS but I am having a problem with the netMsmqBinding under WAS/IIS. In a nutshell, I can implement MEX for a Self Hosted NetMsmq binding application but not WAS/IIS. It seems like WAS is rejecting any of the addresses that I use where I can use any address in the self hosted app. In other words I can do this in self hosted:
<system.serviceModel>
<services>
<service name="Microsoft.Samples.MSMQTransactedSample.OrderProcessorService" behaviorConfiguration="OrderProcessorServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/ServiceModelSamples/service" />
</baseAddresses>
</host>
<!-- Define NetMsmqEndpoint -->
<endpoint address="net.msmq://localhost/private/ServiceModelSamplesTransacted" binding="netMsmqBinding" bindingConfiguration="TransactedBinding" contract="Microsoft.Samples.MSMQTransactedSample.IOrderProcessor" />
<!-- the mex endpoint is exposed at http://localhost:8000/ServiceModelSamples/service/mex -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="OrderProcessorServiceBehavior">
<serviceMetadata httpGetEnabled="True" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<netMsmqBinding>
<binding name="TransactedBinding">
<security mode="None" />
</binding>
</netMsmqBinding>
</bindings>
</system.serviceModel>
Hoever, when I try something similar in WAS, it says no endpoint lisening at address 8000. It won't host the metdata. Can someone help me get metadata or implement MEX for NetMsmq in WAS:
<system.serviceModel>
<bindings>
<netMsmqBinding>
<binding name="MsmqBindingNonTransactionalNoSecurity" exactlyOnce="false">
<security mode="None"/>
</binding>
</netMsmqBinding>
</bindings>
<services>
<service name="Portal.LoadSim.Services.MsmqService" behaviorConfiguration="PortalServiceBehavior">
<host>
<baseAddresses>
<add baseAddress="http://localhost:8000/PortalLoadSimServices10/MsmqService"/>
</baseAddresses>
</host>
<!-- Define NetMsmqEndpoint -->
<endpoint address="net.msmq://localhost/private/PortalLoadSimServices10/MsmqService.svc" binding="netMsmqBinding" bindingConfiguration="MsmqBindingNonTransactionalNoSecurity" contract="Portal.LoadSim.Shared.IMsmqService" />
<!-- the mex endpoint is exposed at http://localhost:8000/PortalLoadSimServices10/MsmqService/mex -->
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="PortalServiceBehavior">
<!-- 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>
You need to add URL access control for your services. This command should work for you:
netsh http add urlacl url=http://localhost:8000/PortalLoadSimServices10/MsmqService user="NT AUTHORITY\NetworkService" listen=yes
To delete the entry
delete urlacl url=http://localhost:8000/PortalLoadSimServices10/MsmqService
HTH
UPDATE: This is not the anwer to your problem. This is what you would do if you wanted to run the services as a self-hosted application and run it under non-standard account. Sorry I was getting it mixed up. I tried using your configuration on a sample application at home and found I had to do two things to get it to work - one, I have to rename the queue to the path and name of the svc file (e.g. PortalLoadSimServices10/MsmqService.svc) and rather than using the base address just browse to the svc file in your IIS host application. You might also need to modify the queue permissions so iis can access it correctly. Let me know if this solves your issue.

WCF Restful Service .NET 4 IIS 7.5 Issues (The message with Action '' cannot be processed)

I have a wcf restful service up and running. I can issue Get/Post with no issues if I start a webservice using WebServiceHost. I tried moving the wcf service to IIS 7.5 on my local box and I can't seem to get it going.
I keep getting the following error anything I try to call anything from from the wcf service: (http://wp9dbytr1k1:8081/service.svc/AnythingHereForGETorPUT). I've tried in virtual directory/Appliances and I get the same issue.
The message with Action '' 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).
if I call the svc file directly (http://wp9dbytr1k1:8081/service.svc), its happy and tells me
"You have created a service.
To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax:
svcutil.exe http://wp9dbytr1k1:8081/FUU/service.svc?wsdl"
The strack trace from Trace viewer hasn't help: Sorry have to add a link, not allowed to post images yet. (ImageLink)
Here's my web.config
<system.serviceModel>
<bindings>
<mexHttpsBinding>
<binding name="NewBinding0" />
</mexHttpsBinding>
<webHttpBinding>
<binding name="WebBinding">
<readerQuotas maxDepth="524288" maxStringContentLength="524288"
maxArrayLength="524288" maxBytesPerRead="524288" maxNameTableCharCount="524288" />
<security mode="None">
<transport clientCredentialType="None" proxyCredentialType="None" />
</security>
</binding>
</webHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="StoredProcBehaviors" name="StoredProcService.DataRetreivalService">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="WebBinding"
contract="StoredProcService.IDataRetreivalService">
<identity>
<dns value="locahost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
contract="StoredProcService.IDataRetreivalService" />
<host>
<baseAddresses>
<add baseAddress="http://WP9DBYTR1K1:8081/" />
</baseAddresses>
</host>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="StoredProcBehaviors">
<serviceMetadata httpGetEnabled="true"/>
<serviceDebug includeExceptionDetailInFaults="true" />
</behavior>
</serviceBehaviors>
</behaviors>
For obvious reasons, this feels like IIS setup since it works with WebServiceHost. I've googled the errors/tutorials on how to set this up and everything seems good to me.
Any suggestions?
Thanks
To create a REST endpoint in WCF, you need, in addition to using the WebHttpBinding, to have an endpoint behavior with on it.
<system.serviceModel>
<services>
<service behaviorConfiguration="StoredProcBehaviors" name="StoredProcService.DataRetreivalService">
<endpoint address="" binding="webHttpBinding" bindingConfiguration="WebBinding" behaviorConfiguration="REST"
contract="StoredProcService.IDataRetreivalService">
<identity>
<dns value="locahost" />
</identity>
</endpoint>
</service>
</services>
<behaviors>
<endpointBehaviors>
<behavior name="REST">
<webHttp/>
</behavior>
<endpointBehaviors>
</behaviors>
</system.serviceModel>
Another option is to use the WebServiceHostFactory in the .svc file, which works like the WebServiceHost. In this case you don't even need the system.serviceModel section in web.config.
<% #ServiceHost Service="StoredProcService.DataRetreivalService" Factory="System.ServiceModel.Activation.WebServiceHostFactory" Language="C#" debug="true" %>

Changing WCF service to require SSL

I have a WCF service which was running fine on a http binding. I've tried to update this to use SSL but i am getting the following error:
"Could not find a base address that matches scheme http for the endpoint with binding WSHttpBinding. Registered base address schemes are [https]."
This only occurs when i set the site to "Require SSL" in IIS 7.5 if I uncheck it it works fine.
Here's my config
<system.serviceModel>
<behaviors>
<serviceBehaviors>
<behavior name="ServiceBehavior" >
<dataContractSerializer maxItemsInObjectGraph="2147483646"/>
<!-- 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" />
<serviceMetadata httpGetEnabled="false" httpsGetEnabled="true" />
</behavior>
</serviceBehaviors>
</behaviors>
<bindings>
<wsHttpBinding>
<binding name="wsHttpEndpointBinding">
</binding>
</wsHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="ServiceBehavior" name="WcfService1.Service1">
<host>
<baseAddresses>
<add baseAddress="http://localhost/WcfService1/"/>
</baseAddresses>
</host>
<endpoint address="" binding="wsHttpBinding" bindingConfiguration=""
name="wsHttpEndpoint" contract="WcfService1.IService1" />
<endpoint address="mex" binding="mexHttpsBinding" bindingConfiguration=""
name="MexHttpsBindingEndpoint" contract="IMetadataExchange" />
</service>
</services>
<serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
I've tried allsorts and nothing seems to get me there, any help is greatly appreciated!
Modify your binding configuration:
<bindings>
<wsHttpBinding>
<binding name="wsHttpEndpointBinding">
<security mode="Transport" />
</binding>
</wsHttpBinding>
</bindings>
And reference that configuration in your endpoint by setting its bindingConfiguration attribute to the name of configuration.
<endpoint address="" binding="wsHttpBinding"
bindingConfiguration="wsHttpEndpointBinding"
name="wsHttpEndpoint" contract="WcfService1.IService1" />
You can also delete the host section with base address because it is not used when hosting in IIS.
In addition to changing the binding configuration settings (as Ladislav mentioned)... Change HTTP in the base address to HTTPS.