WCF Services, Can I view output in a browser? - c#

I feel like this question is so basic that none of the tutorials or documentation even bothers to mention how to do it. I'm familiar with web services on other platforms, but I'm new to WCF services.
I've set up a wsHttpBinding like this (in the web.config):
<service behaviorConfiguration="IdentityServiceBehavior" name="Com.CompanyName.Service.IdentityService">
<endpoint address="/Identityservice" binding="wsHttpBinding"
bindingConfiguration="" contract="Com.CompanyName.Service.IIdentityService" />
<endpoint address="mex" binding="mexHttpBinding" bindingConfiguration=""
bindingNamespace="" contract="IMetadataExchange" />
</service>
I attempt to hit the URL using Fiddler or just a browser and it just gives me a 400 result. I've tried a bunch of different possibilities for what the URL might be, but no dice. I've tried this URL and a few variations on it: http://localhost:61987/IdentityService.svc/Identityservice
If anyone could point me in the direction of the basic information I'm missing here, I'd be very grateful.

You can use the WCF test client to test your WCF services

Related

Is it possible to create an other endpoint in HTTP on the same port?

One of my mate has created a C# WCF service working on Net.TCP on a specific port, it is asked to me if it is possible to create an other endpoint on this WCF service in order to consume it with HTTP protocol on the same port ?
How can I do to consume a WCF service with two differents protocols Net.TCP + HTTP ?
Thanks per advance for your answers :)
Edit : Do you have an example about how to implement a HTTP + Net.TCP endpoints in a WCF service ?
As far as I know, this is completely impossible. But service could work properly over Net.TCP+Http over different port number.
<services>
<service name="ConsoleApp3.TestService">
<endpoint address="" binding="netTcpBinding" contract="ConsoleApp3.ITestService" ></endpoint>
<endpoint address="http" binding="basicHttpBinding" contract="ConsoleApp3.ITestService"></endpoint>
<endpoint address="mex" binding="mexTcpBinding" contract="IMetadataExchange"></endpoint>
<host>
<baseAddresses>
<add baseAddress="net.tcp://localhost:21012"/>
<add baseAddress="http://localhost:21013"/>
</baseAddresses>
</host>
</service>
</services>
Net.TCP Port sharing only is applicable for the scenario that has different service addresses, not the indeed port sharing.
Feel free to let me know if there is anything I can help with.

Multiple endpoints - public/internal

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.

SOAP requests fail with MEX Binding

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>

How to publish WCF service in internet (hosted in wnd service)

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.

Question on how to create WCF silverlight 3 endpoints

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.

Categories

Resources