Update Service Reference is not working in WCF - c#

I am using VS 2012.
I add services reference to my WPF project, but when I've changed my services and updated service reference my Reference.svcmap -> Reference.CS file will be blank and I can't use reference anymore. I can see it in project, but I can't use.
My settings of Services References are :-
Reference.cs file
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.17929
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------

uncheck the Reuse types in referenced assemblies checkbox and put address of your new service in Address textbox.

While configuring service reference append /mex (address of your end point with mexHttpBinding ) at the end of your service URL.
https://service.domain.com/serivce1.svc/mex
This will enable metadata exchange. So Reference.cs will be modified / added (if you are adding service reference for the first time).
Edit : On analysis I found that this issue happens when a service (which implements one ServiceContract) is exposed via more than one end point.
This issue can be avoided by using different Service Contracts (Interface) for each end point and making the service class (service1) implement all these Interfaces.

If you cannot browse the URL, then you will not be able to add the service reference. Try hosting your web service locally in IIS. When you're able to browse the URL, then you can add the service reference.

Unchecking the reuse option the Update Service option works fine.

There are few things you can do first Clean the solution, delete the output directory and the service reference. Restart the Visual Studio and re configure the web service.

It can be caused by Team Foundation source control.
Try to right click on the service ref and choose "Check out for edit..."
Than update service reference again.

Related

C# - How to add a SOAP web service reference to my project?

I am attempting to add a web service reference from an example project into my current VS 2015 C# project. This is what I have in the example project:
To move it over to my new project, I have attempted to copy and paste the "Address" field into my project by right clicking my project and selecting "Add Service Reference". When I do this I get the following error:
There was an error downloading 'http://myserver.com/MyServiceExample.svc?wsdl/$metadata'.
The remote name could not be resolved: 'myserver.com'
Metadata contains a reference that cannot be resolved: 'http://myserver.com/MyServiceExample.svc?wsdl/$metadata'.
There was no endpoint listening at 'http://myserver.com/MyServiceExample.svc?wsdl/$metadata 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 name could not be resolved: 'myserver.com'
If the service is defined in the current solution, try building the solution and adding the service reference again.
How can I go about adding this service reference into my project? I have tried adding it in by using the VS 2015 CMD Prompt with the WSDL /verbose command, but this does not seem to be working. I have the project files and wsdl files for the example, but I cannot get them to work on my solution.
Start your web-service project in iis express by launch debug session then when you get temporary url of your service (like http://localhost:8000/MyServiceExample.svc) you can retrive wsdl from it.
Just replace myserver.com part of url on new one when adding a service reference.
Here you can read how adding service refence is working but in general you need to retrive contract from deployed web service (wsdl) from which vs generates new classes.
Later you should change service url in web.config on deployed one.

Why my webservice method is not updating its parameters in the wsdl?

I modified my webservices and added one new parameter. I re-compile everything and when I ran in my localhost everything works fine. BUT when I deployed into my IIS server the wsdl is not being updated and it simply do not show my new parameter.
What do I have to do for my wsdl to be updated?
Right click on the web reference and click update. It will update the reference.cs file. Then compile and deploy. Make sure it reference the new reference.cs file.
When you say the wsdl is not being updated to show the new parameter how are you trying to access the wsdl? if you are trying to access http://myserver/myservice/service.asmx?wsdl and the updated wsdl is not showing up, try restarting the web application/website on IIS that hosts the service.asmx. If that doesn't solve it try redeploying the code. If on the other hand you are stating that a client application that is consuming the service you have hosted on IIS cannot see the updated wsdl you need to check the code of the client application not your service. If it has a web reference pointing to the URL where your service is hosted then you need to do what Azhar suggested and right click on the web reference and click update. If it has a proxy class generated by wsdl.exe then regenerate the proxy class by using wsdl.exe as follows
wsdl /namespace:MyCompany.MyApp.Services /out:C:\MyServiceProxy.cs http://myserver/myservice/service.asmx
and update the client project with the new MyServiceProxy.cs file which should contain the method with the updated parameters.

Implement mock service with wsdl tool

I'm currently following this tutorial to learn how to implement a mock web service:
http://iandykes.blogspot.nl/2008/06/creating-mock-web-services-in-net.html
The web service that i'm using is a public web service: http://www.webservicex.net/CurrencyConvertor.asmx?WSDL
So i used the wsdl.exe tool to generate a class for that service, like it is explained in the tutorial. I also added the generated .cs file to my Solution project.
I then did the following in Visual Studio to add the Web Service:
Right clicked on my project -> Add Service Reference -> Advanced -> Add Web Reference
In there i added the URL to the web service and then hit the Add Reference button. So now i have a Web References folder in my project with a CurrencyProxy in it (that is how i named it).
The next step that i have to do according to the tutorial is:
In the code behind for this Web Service, change the class definition
so that it implements the interface in the generated code.
That is where i'm actually stuck. Where can i find the code behind file of the Web Service? I'm not sure what to do here.
Could anyone help me out?
When you add Web Service to your project, there will be YourWebService.asmx and YourWebService.asmx.cs under it. In YourWebService.asmx.cs, just replace System.Web.Services.WebService with your interface, which was generated earlier. Implement this interface as you wish and that's it, mock service's done.

Consuming a WCF Service that is hosted in a Windows Service from outside solution

I've set up a WCF Library hosted in a Windows Service using the following walk-through:
http://msdn.microsoft.com/en-us/library/ff649818.aspx
The consumer winforms is in the same solution, which is located locally on my work PC's C: drive.
The walk-through works i.e. the winforms button gives me the correct answer.
If I create a new Solution on the C-Drive with a single Windows Forms project in it I cannot successfully add a service reference to this running service, i get the following message:
The detailed message says the following:
The URI prefix is not recognized. Metadata contains a reference that
cannot be resolved: 'net.tcp://localhost:8526/Service1'. Could not
connect to net.tcp://localhost:8526/Service1. The connection attempt
lasted for a time span of 00:00:02.0020000. TCP error code 10061: No
connection could be made because the target machine actively refused
it 127.0.0.1:8526. No connection could be made because the target
machine actively refused it 127.0.0.1:8526 If the service is defined
in the current solution, try building the solution and adding the
service reference again.
Why can I add this Service Reference ok to a project within the same Solution as the Service but not from a project in a different solution?
EDIT
My colleague found an error in the MSDN article - I have detailed his find HERE
The step by step walkthrough article at MSDN ends unfortunately where it gets interesting, so let's continue here. Because there are many possibilities which may cause the error, I've described several options (= scencarios which may cause the issue) below, which should help troubleshooting:
1st option: Try to specify
net.tcp://localhost:8526/Service1/mex
when you add the service reference to your new client - ensure that the service is installed and running before you do that.
Explanation: The suffix "mex" stands for "metadata exchange" and allows Visual Studio to download details of the WCF contract. This suffix is also used in the walk-through example, it was added automatically (you will see it in the Address field if re-open the added service reference by right-clicking on "Configure Service-Reference...").
2nd option: What I noticed when I tested the walk-through is that it helps sometimes to right-click on the service reference and select in the contect menu "Update Service-Reference".
After a while in the systray you can see the balloon message "Your service(s) have been hosted.", after which you can start the client within the same solution. In this case, the service has been temporarily created but is not deployed permanently - which means, if you stop debugging, it is removed. As a result, you can't use this service from a remote PC, it is just visible within the solution in Visual Studio. Visual Studio internally invokes the tool
WcfSvcHost.Exe /Service:<Service1Binary> /Configuration:<Service1Config>
supporting it with the right parameters to register the service properly (you can find this tool in Visual Studio's Common7\IDE subdirectory, and there is also WcfTestClient.Exe available - a tool which acts as a client, very useful to debug WCF).
For instance, if you have stopped debugging, and launch the client.exe from Windows Explorer outside of Visual Studio, then it does not find the service and you're getting exactly the error message you have described in your question.
There are two interesting links regarding this matter at Microsoft:
Problem with Metadata Exchange and Publishing Metadata
Note that this is different from deploying it as described in the 3rd option.
3rd option: Have you used InstallUtil to deploy the service? In this case it can happen that you have accidently removed the [...]/bin/Debug subdirectory and the service fails to start, because the .EXE file is missing.
Note: This can be avoided if you're using a ServiceInstaller project, which copies the binaries before the service is registered. Or - if you want to use InstallUtil for simplicity - you can copy the service binaries to a target directory (including the .config files and .dlls) before you register it.
4th option: If you run the service on a remote computer, you need to specify the proper host name or IP address of the host instead of localhost, and you need to ensure that the personal firewall (windows firewall or 3rd party) doesn't block the port 8526 (the port number which was used in the example). Specify an exception to allow this port for incoming and outgoing traffic.
5th and final option (UPDATE): Naming conflict - Service1 is the service but also the class name in the Wcf library. Either fully qualify the class name you're using from the WCF library in the service, i.e. WcfServiceLibrary1.Service1 or rename the class. Whytheq has found it himself with a colleague and as posted it here.
More reading: Check out this article, which I've found recently: "WCF: a few tips". It explains very well troubleshooting WCF. The only change I would made to the console hosting example is to replace the using statement by a
ServiceHost host = new ServiceHost(typeof(Service));
try
{
host.Open();
Console.WriteLine("WCF Service is ready for requests." +
"Press any key to close the service.");
Console.WriteLine();
Console.Read();
Console.WriteLine("Closing service...");
}
finally
{
if (host!=null) {
host.Close();
host=null;
}
}
If you want to know more about the reason why, check out this article: "Proxy open and close".
You can get round this as follows:
Browse the service's WSDL URL and save the WSDL to a local file.
Then make the following changes to the file:
Remove the namespace prefix from the name used for the wsdl:binding i.e. change
name="wb:wsclocks-inboundSoapBinding" to be
name="wsclocks-inboundSoapBinding"
Change the binding attribute of the wsdl:port attribute to match, and also remove the namespace prefix from the value of the name attribute, so it is just wsclocks-inbound.
Then run svcutil /o:Client\WBServices /noConfig

Adding a service reference to a website

I am trying to add a service reference to my website. When I add the service reference to a WPF application I get a reference.cs file that I can edit and add attributes to. When I try to do the same thing in a asp.net website there this file isn't present. I have also tried looking on the file system and the reference.cs isn't present. Can anyone provide some guidance?
EDIT:: Im using VS2010 and I need to edit the reference.cs to add [Webget] and [WebPost] attributes
If you want to manually edit a service stub, consider using svcutil.exe.
In Visual Studio, right-click on the reference under the "Service Reference" section of the Solution Explorer and click "View in Object Browser". Then, in the Object Browser, under the namespace for the reference, right-click on any of the properties and select "Go to Definition". This will load up "Reference.cs" file.
Hope this helps!
Edit:
Also worth noting is that the classes generated for you are partial classes, so it may be beneficial to consider extending them in a separate file so that you can still "Update" the reference and not have the generated code overwrite any changes you make. This would all depend on what you're planing on modifying though.
Depending on the version of VS it will create a folder under the project root. In my case under VS2010 I added a ref to http://www.webservicex.net/stockquote.asmx?WSDL, set the namespace to ServiceReference1 and it created a folder in the project root called \Service References\ServiceReference1 under which it stored all the ref files including Reference.cs
If you are not seeing this folder then there may be something wrong at your service that VS is unable to query the WSDL and generate the files. Try the stock service above to test.
And editing the generated files is usually a bad idea as they can get regenerated when you refresh the reference. Unless you want to rip the generated code out and never refresh it again.
UPDATE:
Seems like that webservicex service is slow, try this
Also, seems like there is a diff between "Web Reference" and "Service Reference". See here. But ultimately it creates a sub folder in your project root called either "Service References" or "Web References" with the sub folder of whatever you named your reference.

Categories

Resources