Failed to add a service reference to WCF service - wcf

When attempting to add a service reference to a WCF service to my .NET project I am getting an error:
Failed to add a service. Service metadata may not be accessible. Make sure your service is running and exposing metadata.
After doing some research I decided to add a metadate exchange endpoint to my service:
<endpoint
address="mex"
binding="mexHttpsBinding"
contract="IMetadataExchange"/>
Now, after adding the enedpoint I am getting a different type of error:
Could not find a base address that matches scheme http for the endpoint with binding BasicHttpBinding. Registered base address schemes are [https].
What am I doing wrong here?
If I open service in the browser, it works just fine:
https://alias.domain.com/ProjectName/MyService.svc?wsdl

mexHttpBinding is only for http:// but as your service is exposed over https:// you need to change it to mexHttpsBinding.
See here: https://msdn.microsoft.com/en-us/library/aa395212(v=vs.110).aspx

Solved!
The issue was that some XSD references in WSDL, schemaLocation in particular. For some reason schemaLocation used machine name instead of the domain name. After I fixed that I was able to add a reference to the service

Related

SharePoint 2010 hosted wcf and castle windsor

I am trying to work out how to host a wcf service in sharepoint 2010 which uses castle windsor. I can host my own standard custom web service without any issues by using one of the service factories from http://msdn.microsoft.com/en-us/library/ff521586(v=office.14).aspx.
Setting up a normal wcf service with castle windsor involves modifying the global.asax but, as this is not recommended for SharePoint, I have created an HttpModule which sets up the container and I have updated the web config to use it by creating a feature reciever.
My problem is where to go next. I am using the MultipleBaseAddressBasicHttpBindingServiceHostFactory for my service because that dynamically configures all of the endpoints for the service based on the IIS configuration but in order to use castle windsor it looks like it is necessary to change to using the supplied Castle.Facilities.WcfIntegration.WindsorServiceHostFactory. I have tried just switching over to see what happens but that does not seem to work. I get the following error
Error: Cannot obtain Metadata from <svc url> If this is a Windows (R) Communication Foundation service to which you have access, please check that you have enabled metadata publishing at the specified address. For help enabling metadata publishing, please refer to the MSDN documentation at http://go.microsoft.com/fwlink/?LinkId=65455.WS-Metadata Exchange Error URI: <svcurl> Metadata contains a reference that cannot be resolved: '<svcurl>'. The requested service, '<svcurl>' could not be activated. See the server's diagnostic trace logs for more information.HTTP GET Error URI: <svcurl> There was an error downloading '<svcurl>'. The request failed with HTTP status 404: Not Found.
I assume this is because I haven't configured an endpoint for the service but the few examples I have seen online do not seem to either.
Has anyone managed to get castle windsor and sharepoint wcf working - preferably with dynamic configuration if possible?
The error message that you are getting is that the metadata of the service is not published. To do this you need 2 things:
A mex endpoint for your service:
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
And service meta data turned on in service behavior:
<serviceMetadata httpGetEnabled="True" />

What is the use of WCF endpoint address

I am new in WCF. I know that we have to write endpoint in config file at service end and as well as client end. suppose I have multiple endpoint like
<services>
<service name="YourNamespace.YourService" behaviorConfiguration="Default">
<endpoint name="Default"
address="http://YourServer/Services/MyService"
binding="basicHttpBinding"
contract="YourNamespace.IYourService"/>
<endpoint name="TCP"
address="net.tcp://YourServer/ServicesTCP/MyService"
binding="netTcpBinding"
contract="YourNamespace.IYourService"/>
<endpoint name="Dual"
address="http://YourServer/Services/MyService/Dual"
binding="wsDualHttpBinding"
clientBaseAddress="http://localhost:8001/client/"
contract="YourNamespace.IYourDualService"/>
<endpoint name="mex"
address=""
binding="mexHttpBinding"
contract="IMetadataExchange"/>
</service>
</services>
we know that we can not create proxy at client side with endpoint address like
http://YourServer/Services/MyService/Dual or
net.tcp://YourServer/ServicesTCP/MyService
rather if we need to create proxy at client side then we need to provide mex endpoint address. so I just do not understand what is the use of endpoint address?
When we create proxy at client side and call service then we just do not understand our proxy is using what endpoint address to connect to service?
That is why I just want to know how endpoint address come into role?
I know that we can write separate mex endpoint for tcp in config file as a result we can create proxy with that mex url as a result when client would connect to service then tcp protocol will be used for communication but for other http endpoints one mex endpoint works fine.
My important question is which I really like to know that suppose i have 3 endpoints like basichttp,wshttp,wsdualbidning then one mex endpoint works for all of them to create proxy. so tell me in that case when client connect to service then which endpoint address will be used to connect to that service?
It will be great help if some one discuss this issue with great detail and with sample config entry and as well as sample service code?
UPDATED Part
Tom Redfern said...service endpoints is not required in case of internal use. suppose I have developed a service which is hosted in console apps and other client need to connect to that service. so tell me in this case how client can connect to service without proxy class and call various method of service. I just like to know without proxy how can I connect and call various method of wcf service. please come with some sample code for client side just to show how programmatically I can connect and call various method of wcf service without proxy.
An endpoint needs a way of addressing it. This is both fundamental and reasonable.
Your argument that the client only requires a metadata endpoint address in order to resolve the actual service endpoints only holds true when you are exposing a metadata endpoint (which is by no means required) and when the consumer has no other means to consume the service (perhaps the service is public).
Most services are developed for internal consumption where the ability to bind directly to an endpoint via referencing a shared types assembly (rather than via a service proxy) is commonplace. Knowledge of the endpoint address in these instances is absolutely required.
If you read about the history of UDDI, this was designed as a means to distribute service metadata to consumers who would have no need to know anything else about the service. However, how often do you see a UDDI server? I have seen it used in exactly one company (I have worked in about 20 in total).

how to use WCF for web application

i need to use WCF Service with in my web application.
I ama new to wcf.
i created the service and add the service reference in my web application.
It shows the http:localhost in end point address.
endpoint address="http://localhost:52123/GeneralService1.svc"
i am confused to use the local host for access the wcf in web.
Is there any way to communicate with wcf / how to enable the connection.
Thanks in Advance
Pooja
A WCF endpoint has its ABC.
A - Address
B - Binding
C - Contract
<endpoint address="" binding="wsHttpBinding" contract="WcfService2.IService1">
You can change the address, by putting the Url of your deployment server, where the service would be hosted in production.
Read this for more details of WCF endpoint ABC
You can modify this address in the web.config file, to the url, while deployment.

All about WSDL vs MEX?

I am not able to open the meta data url http://localhost:8082/Tasks/mex, even though
I've added the mexHttpBinding in the config file. Can I view this MEX endpoint in a browser?
The config files look like:
<endpoint address="mex" binding="mexHttpBinding" contract="IMetadataExchange" />
Questions:
Is MEX is different from WSDL? If not, then why do we require a MEX endpoint over WSDL?
In the WSDL, I see the WSDL type information is missing. Is it by default? Can I look at the type information in WSDL?
Check out serviceMetadata for more information regarding the WCF configuration file.
To answer your questions though, MEX is a newer W3C standard for the presentation of Service description information; WSDL was the previous method. If you need to allow older clients to access your service description information, you may have to expose that information via WSDL.
The information for exposing your service description information as WSDL (httpGetEnabled) is also in the link provided above.
Also, try using the wcftestclient.exe to access your WCF service. It provides more functionality and information than a browser.
Aakash, Did you add a service behavior with a <serviceMetadata> element? It can be empty, i.e. <serviceMetadata />, but it must be present. The service definition needs to reference the service behaviorConfiguration. Check out the following for examples:
http://www.request-response.com/blog/PermaLink,guid,c9513d28-f580-4a33-b4e8-c15476799a9d.aspx
If you look at that endpoint, you'll see it looks like every other endpoint. There's even a service contract (IMetadataExchange). You can look at System.ServiceModel.Description.IMetadataExchange and see what that contract is all about.

WCF Service Updating the Service URL (Easy Way)

There is a WCF service that I was using and now it is pointing to a new URL. Is there anyway to go and change the URL without having to delete the service from the project and add it again using the new URL.
The problem with deleting the service is stupid TFS is giving problems. Any suggestions how I can update the service url without deleting the service?
In general the url a client is pointing to is defined in the app/web.config using the endpoint element. So all you have to do is modify the address attribute to point to the new url:
<endpoint address="http://newUrl"
binding="..."
contract="..." />