I have an existing web WCF web service which can be called by a Windows form via a proxy.
I wish to also be able to call this service from jQuery.
I am following the following article: http://www.codemag.com/Article/1308041
However, I am stuck because the article says to add the following code to the web.config of the service:
<services>
<service
behaviorConfiguration="ProductServiceBehavior"
name="ProductServiceHost.ProductService">
<endpoint
address=""
binding="basicHttpBinding"
contract="ProductServiceHost.IProductService" />
</service>
</services>
My config file already has this for my service:
<service
behaviorConfiguration="MyApp.EndPoint.Services.TrainingServiceBehavior"
name="MyApp.EndPoint.Services.TrainingService">
<endpoint
address="" binding="wsHttpBinding"
contract="MyApp.EndPoint.Services.Interface.ITrainingService"
name="wsHttp"
bindingConfiguration="wsHttpBindingConfiguration">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
I've tried replacing the binding with the basicHttpBinding, but I then get errors when calling the service from my Windows form, such as "The remote server returned an error: (415) Unsupported Media Type."
Should my service have both of the above bindings?
Basically, my changes fail at the step: You should run your existing application at this point to ensure that everything still works.
Can anyone point me in the right direction?
I added the following to the config file:
<service
behaviorConfiguration="MyApp.EndPoint.Services.TrainingServiceBehavior"
name="MyApp.EndPoint.Services.TrainingService">
<endpoint
address=""
binding="basicHttpBinding"
contract="MyApp.EndPoint.Services.Interface.ITrainingService" />
</service>
I also added the following decoration:
[WebInvoke(Method = "POST",
BodyStyle = WebMessageBodyStyle.WrappedRequest,
ResponseFormat = WebMessageFormat.Json,
RequestFormat = WebMessageFormat.Json)]
However, my Windows form app now gets the following error when it calls the service:
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.
The error is presumably because I have two services in the config file with the same name. If I give the new service a new name, would I have to create a new method?
I'm trying to use the same method, but this seems to be impossible.
I think you can leave your current configuration as it is. The changes made in the article are made to a very basic configuration in order to make the configuration of the existing service explicit (by stating the binding, the contract and the behavior). Your configuration already states the service explicit.
What you should do is add a new configuration for jquery to use as described in the article: add a new behavior and add a new endpoint.
Related
I want to expose 2 endpoints on my WCF service. First offers standard methods for users over HTTP, second one offers "administrator-only" method ovet net.tcp.
I have only 1 class, that implements both ServiceContracts exposed by endpoints, like that:
public class ComputingModuleProvider : IComputingModuleProvider, IComputingModuleAdminProvider
My App.Config looks like this:
<services>
<service behaviorConfiguration="ComputingModuleBehaviour" name="ComputingModuleProvider.ComputingModuleProvider">
<endpoint address="ComputingModuleProvider" binding="basicHttpBinding" contract="ComputingModuleProvider.IComputingModuleProvider" />
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<endpoint address="ComputingModuleAdminProvider" binding="netTcpBinding" contract="ComputingModuleProvider.IComputingModuleAdminProvider" />
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8091/ComputingModuleProvider"/>
<add baseAddress="net.tcp://localhost:8092/ComputingModuleProvider" />
</baseAddresses>
</host>
</service>
</services>
Now the situation is that I have the service on the server-computer in our office and the client is on my personal computer (but both of them are connected to local network).
Still, I had to add an exception to server firewall and allow communication on ports 8091 and 8092 in order to be able to add service reference and generate proxy on client side. With this exception allowed, I can add service reference using both net.tcp and http base adress.
The problem is, that I see both ServiceContracs for each base adress, like in the image below:
I expected, that for net.tcp I would only see IComputingModuleAdminProvider and for http, I would see IComputingModuleProvider.
I also tried to exclude port 8092 from allowed ports on server firewall - that resulted in being able to add service reference only by using http base adress, but still, I could see both Service contracts exposed, like in image above.
So the administrator-only method is available over http as well.
Question:
Am I doing something wrong in my app.config file or is this the standard behaviour? I know I am on the same local network, but still, I had to add the exception in firewall, thus I expected, that IComputingModuleAdminProvider would not be available over http protocol.ยจ
UPDATE:
Ass suggested by Otiel, if I create new ServiceContract like this:
public class ComputingModuleAdminProvider : IComputingModuleAdminProvider
And mark it as a new <service> in App.Config, I can separate the admin and standard interface.
I have an odd problem with some services. I am not the developer I am the sysadmin.
We have some SOAP services running in a development environment. Some SOAP services started to fail. Here is one example. These are both coming from the same web config.
<endpoint address="http://<URL>/<folder>/service.svc"
binding="wsHttpBinding"
bindingConfiguration="wsHttpBinding"
contract="eConsentSvc.IeConsent"
name="WSHttpBinding_IeConsent" />
This one does not:
<endpoint address="http://<URL>/<folder>/service.svc/mex"
binding="wsHttpBinding"
bindingConfiguration="wsHttpBindingText"
contract="MetaDataSvc.IMetaData"
name="WSHttpBinding_IMetaData">
</endpoint>
This 2nd one throws a 404 error. The error generated is this:
There was no endpoint listening at http:////service.svc/mex that could accept the message.
The obvious difference is the "/mex." The developers insist that this has to be there so it has to be there. Why would it throw the 404 error with the MEX there?
If I remove the /mex then the service runs and generates the XML document it is supposed to create.
Please help. I am completely stumped.
In this endpoint one cannot specify binding="wsHttpBinding"
it has to one of the mex* bindings, for example: mexHttpBinding.
Another way would be to simply add another endpoint <endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>
<endpoint address="http://<URL>/<folder>/service.svc/mex"
binding="wsHttpBinding"
bindingConfiguration="wsHttpBindingText"
contract="MetaDataSvc.IMetaData"
name="WSHttpBinding_IMetaData">
</endpoint>
In a WCF service hosted in IIS, I'm trying to set up multiple endpoints. One for SOAP and one for SOAP12. Per the MSDN documentation, I've edited Web.config like:
<services>
<service name="MyNamespace.MyClass">
<endpoint address="" binding="basicHttpBinding" contract="IContract" />
<endpoint address="Endpoint2" binding="wsHttpBinding" contract="IContract" />
</service>
</services>
This doesn't seem to have any effect. There is no answer on URL:
http://localhost:51454/MyClass.svc/Endpoint2
If I change IContract to IContract2, I get the error:
The service '/MyClass.svc' cannot be activated due to an exception during
compilation.
So the Web.config I'm editing is the one being used.
Changing the binding for the default address from basicHttpBinding to wsHttpBinding doesn't have any effect. The WSDL stays the same.
The WSDL includes this bit, which seems to suggest that it's running using a generated binding:
<wsdl:service name="TapasSim">
<wsdl:port name="BasicHttpBinding_IContract"
binding="i0:BasicHttpBinding_IContract">
<soap:address location="http://localhost:51454/MyClass.svc"/>
</wsdl:port>
</wsdl:service>
Why does the WCF service not use the configuration from Web.config?
Why does WCF not listen on /Endpoint2 with the SOAP12 binding?
Why does the default endpoint not change from basicHttpBinding to wsHttpBinding?
Try adling a base adress for the endpoint:
<service name="namespace.Service">
<host>
<baseAddresses>
<add baseAddress="http://localhost:51454/myclass.svc"/>
</baseAddresses>
</host>
// endpoint omnited
Or try adding a slash before the address:
endpoint address="/Endpoint2" binding="wsHttpBinding" contract="IContract"
The MSDN article is correct and there is nothing wrong in your configuration. I created a WCF client using VS and was able to successfully call using
http://localhost:51454/MyClass.svc/Endpoint2
Apparently, it does not appear as a valid url from browser. try consuming from a client using the second url and it should work
The problem was the service name:
<service name="MyNamespace.MyClass">
The class name was wrong. When you enter a wrong contract interface, WCF throws an error. But a wrong class name is silently ignored. That explains why it fell back on the default configuration.
I have a windows service on my laptop, which hosts a WCF service. I would like to use these service on my ASP.NET website, which is on external ASP.NET server.
Could you help me, how to do this?
Is it necessary a specific laptop configuration for that? What should I configure?
And binding, what type will adequate? .. Right now, I've got:
<service behaviorConfiguration="WcfServices.InfoBehavior" name="MyProgram.WcfServices.Info.Info">
<endpoint address="" binding="wsHttpBinding" contract="MyProgram.WcfServices.Info.IInfo">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
<host>
<baseAddresses>
<add baseAddress="http://localhost:8732/Info/" />
</baseAddresses>
</host>
</service>
UPDATE:
Right now, my client app is still on my laptop (it is not publish yet).. This is my client code:
<client>
<endpoint address="http://localhost:8732/Info/" binding="wsHttpBinding"
bindingConfiguration="WSHttpBinding_IInfo" contract="ServiceInfo.IInfo"
name="WSHttpBinding_IInfo">
<identity>
<dns value="localhost" />
</identity>
</endpoint>
</client>
I don't know, what binding use.. what port, what settings should be changed on my laptop?
Unless your laptop has its own fixed IP address exposed externally (most unlikely) I think you will find it hard to do this directly.
You might consider using Azure Service Bus to broker message exchanges: I believe this is one way to solve the problem of accessing a service hosted on a non-constant IP address or behind a firewall/NAT.
Or you could consider changing your design to turn things the other way around. That is, when it is connected and running, your laptop service connects to a service hosted on the ASP.NET box, over a duplex binding, with your current service contract as the callback contract.
If you have a WCF service running on your laptop hosted via ServiceHost you'll need to duplicate that configuration in your ASP.NET web.config file, as well as add a "service.svc" file which is referenced to the Interface of your service.
You should change localhost with real external facing IP address of your laptop and it could work if your router at home has no firewall. Change it in both client and server endpoint address.
I wanted to consume a WCF service with a silverlight application and a asp.net mvc application, and I'm having difficulties to configure the service to support both requests.
these are my endpoints for the WCF config file.
<service behaviorConfiguration="behaviorAction" name="Uniarchitecture.ProdutoService.ServiceImplementations.ProdutoService">
<endpoint binding="wsHttpBinding" bindingConfiguration="bindingAction" contract="Uniarchitecture.ProdutoService.ServiceContracts.IProdutoService">
<identity>
<dns value="localhost"/>
</identity>
</endpoint>
<endpoint address="" binding="basicHttpBinding" contract="Uniarchitecture.ProdutoService.ServiceContracts.IProdutoService"/>
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
</service>
I'm getting the following error:
A binding instance has already been associated to listen URI 'net.tcp://localhost:10377/ProdutoService'. If two endpoints want to share the same ListenUri, they must also share the same binding object instance. The two conflicting endpoints were either specified in AddServiceEndpoint() calls, in a config file, or a combination of AddServiceEndpoint() and config.
The problem is trying to use two endpoints with two bindings... You can use multiple endpoints on the same service here, but they need to use the same binding.
And since Silverlight only supports BasicHttpBinding you're kind of stuck with it.
<service behaviorConfiguration="behaviorAction" name="Uniarchitecture.ProdutoService.ServiceImplementations.ProdutoService">
<endpoint binding="**basic**HttpBinding" bindingConfiguration="bindingAction" contract="Uniarchitecture.ProdutoService.ServiceContracts.IProdutoService"/>
<endpoint address="" binding="basicHttpBinding" contract="Uniarchitecture.ProdutoService.ServiceContracts.IProdutoService"/>
</service>
In your config, the addresses of the two endpoints are the same. With HTTP bindings, you can have multiple endpoints for a service, but you need to specify different addresses for them. Change the address of the basicHttpBinding endpoint to fix this problem.