I have a WCF service that is running fine on our old IIS server. This service has both methods and Classes it exposes, all set up properly using [ServiceContract], [OperationContract], and [DataContract]. The service works fine on the old server. The service is only visible on our local intranet.
We are trying to move to a new IIS server. Other ASP.NET web sites work on the new IIS server. Now, in the client app code, if I try to "Add Service Reference" I am able to successfully add a service reference to the new IIS server. The problem is that while the methods work, the Classes from the WCF service are not visible on the client app. If I take an existing service reference and in the app.config file if I change the url to the new server, everything works. I looked at the WSDL files and both have the Classes in them.
I have checked the "Roles and Features" on both servers and do not see any difference in the relevant items. What am I doing wrong?
Ok so the link provided in the comment above actually solved it. Thanks Lex Li
stackoverflow.com/questions/3000209/service-reference-not-generating-client-types
when I took Abraham Qian's suggestion and tried to add a new service reference to the old server, it was doing the same thing as the new server, not showing the classes. This told me it was a visual studio issue. I then tried Lex Li's suggestion and that solved my issue. As a short recap of the fix:
When you add a new service reference, go to "Advanced..."
By default, "Reuse types in all referenced assemblies" is selected. Change this to "Reuse types in specified referenced assemblies"
In the box below that option, check "mscorlib".
Finish adding the service reference as usual.
Once I did this, it fixed my issues. Thanks for everyone's help!
Related
I am really new in services and are having some problems with one issue. The fact is, i have a WSDL of a SAP system and i need to create a Web API in Visual Studio based on it.
I passed some time searching for tutorial's of how to do that but don't have lucky. Someone would help me, explaining the concept or sending some tutorial where i could understand how to do that? I am completely lost and i need it for my job.
If anyone could help me i would stay quite grateful. Thank you everyone for the support.
Just host the WSDL in ur IIS i.e Create an application in IIS pointing to the directly that contains the WSDL.
And add service reference to the WSDL by pointing to the IIS Url of the application.
Then in config, change it to point to actual implementation of the service.
If you have WSDL of the service you might be able to use ServiceModel Metadata Utility Tool (Svcutil.exe) to generate your WCF client proxy with all the required contracts for it. Here is another link on generation and answer with an example, plus another example.
I am trying to migrate my code from normal wpf application to Universal Windows Platform.
Previously I have used VS 2012 for Developing my WPF application And its working fine. Now I want to use the same application for mobile also.I found UWP as a solution for it. Now I am using vs 2015 . But here in vs 2015 I am unable to find Web Reference Option I am able to see only Service Reference. Actually My situation is I am Dynamically taking Ip Address and port number from User Based on the request I am connecting to that particular services like
public const string GET_SKU_DETAILS = "http://{0}:{1}/OmniRetailerServices/SkuServices/getSkuDetails?skuID={2}";
So like this I am connecting to particular Remote servers for accessing services.
And I did this using Web References in vs 2012. But Here in vs 2015 I am not able to find Web Reference. So My Question is How can I do this in UWP application Using VS 2015.
Please Help me to solve this Issue.
Thanks In Advance.
Web references (ASMX web service clients) are considered as legacy even in classic desktop applications, such as WPF. Service references (WCF service clients) are their successor and as you already noticed, they are available in UWP apps.
Just create a service reference instead of a web reference. You should be able to create it by pointing at the same WSDL as you did to create a web reference.
You can change the endpoint URL when creating an instance of the client proxy:
// use the base URL without the method name
var url = String.Format("http://{0}:{1}/OmniRetailerServices/SkuServices", hostname, port);
var client = new SkuServicesClient(new BasicHttpBinding(), new EndpointAddress(url));
To invoke the web method, call the corresponding method on the generated proxy:
var result = await client.GetSkuDetailsAsync(argument);
Not knowing the details about your service, I tried to come up with reasonable URL value and names in my code to match the info you have provided. It should be enough to get you going even if they won't be identical in your case.
Yes you can. Just proceed as if you gonna add a new service reference (Yes I now that you need to add a web reference) then on the bottom left of the "Add Service Reference" window, click on "Advanced" option. Then, again on the bottom, you see "Compatibility" and near the "Add Web Reference" button, now got it! :)
you can't do this. you need to find another way like HttpClient.
HttpClient is the easy way to consume web services.
https://blogs.windows.com/buildingapps/2015/11/23/demystifying-httpclient-apis-in-the-universal-windows-platform/
I have created a WCF service.
I am now following tutorials on how to consume this service, and the way I've been instructed to do this is to...
"..note the http address and port that Visual Studio is using to run you WCF webservice. It may look like this ([LOCAL HOST ADDRESS]). You will need this url from within the Windows Form to add a reference to the WCF service.."
http://www.thebestcsharpprogrammerintheworld.com/blogs/create-and-consume-a-wcf-windows-communication-foundation-service.aspx
Now, that's fine. But if I'm literally going to copy and paste this url into my application it will no longer be relevant to a live environment will it?
Is this really the best way to point to a WCF service in a solution?
You will see that in your app.config file the url is saved. If you deploy your service to a live server you will only need to change the config to look at the new url.
Hope I understood your question.
Using wsdl.exe /l:CS /serverInterface, I generated a C# interface from a WDSL document. I've implemented that interface on a WCF class. The resulting service runs locally:
http://localhost:51454/TapasSim.svc
This shows the default site. The problem appears when I append ?wsdl to the URL:
http://localhost:51454/TapasSim.svc?wsdl
Unlike what I expected, this link does not return a WDSL document! Instead, it points back to the exact web page you get without the ?wsdl. As a result, I cannot reference the web service. If I run svcutil.exe it gives this error:
If you were trying to generate a client, this could be because the
metadata documents did not contain any valid contracts or services or
because all contracts/services were discovered to exist in /reference
assemblies. Verify that you passed all the metadata documents to the
tool.
But I would expect that error to have the same cause as the lack of reply to ?wsdl.
What could cause a WCF .svc service not to generate WSDL?
As it turns out, the problem was mixing two technologies. wdsl.exe belongs to the older "Web References" that predate WCF. The newer tool svcutil.exe is meant for generating WCF "Service Reference" interfaces.
So what happened was that WCF looked for [ServiceContract] and [OperationContract] attributes. When it couldn't find any, it silently did nothing.
The silent suppression of this condition is annoying, to say the least. An error like No service with [ServiceContract] attribute found would really have helped.
Note that you can manually add [ServiceContract], but that will leave you with half "Service Reference" half "Web Reference". The result probably will not work.
I had a problem with getting the WSDL via the IE window provided by starting the debugging session. I had to use a separate window, ensuring I put the HTTPS in the URL.
We are hosting our services on 443 (SSL). When you start up the debugger, even though the IE windows shows http: (80), it was listening for traffic on 443. FYI, this is controlled via the project level setting SSL Enabled
What do I need to call a web service over https in C#?
Do I need to get the certificate form the site? How do I use this to call the web service?
There's nothing special or different for calling a web service over https than over http. You generate a client proxy from the WSDL using either svcutil.exe (or Add Service Reference in VS) or wsdl.exe and invoke the method. The lower level classes HttpWebRequest and HttpWebResponse will eventually take care of the actual call and certificates but it should be transparent for your code. Of course the server hosting the web service needs to provide a valid certificate.
I take that you are using Visual Studio to create your projects, if you are it is pretty easy to do. I take that you have the url for the web service that you would like to connect to and it starts with HTTPS.
In your project in the solution explorer (assuming you using Visual Studio), you should see a node saying "References" and another one saying "Web References". Right click on the "Web Reference" and then basically follow the wizard. It is pretty straight forward. You can spec your own Namespace. I usually use the format SomethingAPI. Then use the API as you would like any other object in your project. You will get the intellisense and all.
There might occur known problems with some certificates though. See http://support.microsoft.com/kb/823177/en-us
Do you have a client certificate that has been supplied by the provider of the web service?
If so, there are various different ways of doing this depending upon which version of .NET you are using. What version are you using, and are you limited in how you can generate your client proxy classes?