I am having problems connecting to this soap web service via a C# Xamarin.iOS app. I first tested it in a Windows form application and got it to work just fine. However trying to switch it over to a Xamarin.iOS app has been a royal pain.
For the Windows form, I simply used SvcUtil to create the output.config proxy settings and Service.cs file (AllPayData.cs in this case). Then added the contents of the config file to App.config and added the .cs file to the project. I can't follow the same procedure with my Xamarin app, mainly because there is no .config file to add the proxy to.
Following various Xamarin tutorials and examples, I came across the Silverlight tool SlSvcUtil, which created similar files as the other tool but the proxy file was simpler and the .cs file was made up all of async based methods. Wasn't too difficult to adjust to the change of the async methods, the tricky part was just trying to understand how the proxy could or should be tied into all of this. many of the tutorials showed creating an Endpoint object and using BasisHttpBinding to setup the proxy. Unfortunately I ran into this really annoying 415 error.
There was an error on processing web request: Status code 415(UnsupportedMediaType):
Cannot process the message because the content type 'text/xml;charset=utf-8'
was not the expected type 'application/soap+xml; charset=utf-8'."
I tried many different types of bindings including BasicHttpsBinding and WsHttpBinding along with many different options. I attempted to copy the setup verbatim from both of the .config files created by both tools (first one was WsHttpBinding, second one was BasicHttpBinding), but that still yielded error 415.
To me this error simply means that the requests I am sending to the API are in the wrong content type and are expected in a soap envelope (as expected). However, I have no idea on how to specify the content type within the bindings. :(
I re-added the first .cs file created by the first tool again (the one that worked with the Windows form, and attempted to apply the same binding code to it. I came up with an error indicating that MonoTouch does not allow dynamic creations of proxies. Boooo...
I attempted to add it as a web service by right clicking on my solution. It'll add all the mapping just fine, but nothing will be generated in the reference.cs file. I tried copying and pasting the existing .cs files that I already had into reference.cs, but still wound up with the same errors.
What am I missing here?? If all else fails, will I have to resort to manually making the soap api calls with C#? Or will that even work?
Related
I am trying to test the possibility to convert all my WCF service to WebAPI but so far it's a mess. WCF is easy because you create a default project and add 1 or 2 sample method that return anything then add as a service by using the http address and it works out of the box.
On WebAPI you add connected service and type the address and it throw errors so obviously out of the box it has errors and is missing stuff to actually work.
My question is what is missing to WebAPI made with .NET6 to be able to be connected to ?
Following Microsoft example what i should do is to run the service obviously. Then use the path of the json file generated by swagger and input that in the URL of the connected services, give it a namespace and a classname and your good to go.
Step 1 : Running the service
This works i can call the basic 3 method i made for test purpose that return string, List<string> and List<List<string>> and i can execute the "tryout" button and they output everything that it needs
Step 2 : Copy the json file path provided by Swagger
I assumed that this url is good by default. I can click it and i see the definition which seems good.
Step 3 : Create and empty console app and add the connected service
When adding the connected service i pick OpenAPI as it's the only option anyway.
Then it asks for File or URL that i put my value form the service that is running. In this case this is : https://localhost:44341/swagger/v1/swagger.json. I then choose the namespace of WebTest1 and classname of WebTest2 as i dont care and click next
Step 4 : Configuration progress
This is where i have the error which is where i see that the service that can actually run cannot be connected to
Checking project for required NuGet packges... Downloading service
reference from https://localhost:44341/... ErrorFailed adding service
reference(s). Failed to download metadata file from :
https://localhost:44341/.
I finally figured out the temporary fix. I was also able to copy this project over to a colleague and the issue is the same. The problem lies into Visual Studio defaulting for some reason on the debug option of IIS Express which does properly run the service when you press F5 and your browser open normally and you can test things out. The problem is that when you project runs under IIS (actually configured like it would be the real deal) or IIS Express (the only IIS option in the debug setting) you cannot from another application connect to that service.
However if you switch the debug option to the project name and run your WebApi with that instead it also works as expected from the browser that it open but you now can actually add that service from another application without any error.
Personally i have a third option which is WSL which i "guess" is the linux sub system i can't tell as this crash when i try to start and there is no help for the UI of Visual Studio to help understand these menu options.
Now i still have a problem to attach to one running in a real IIS which is probably linked to the same reason why IIS Express debug doesn't work. So i now know that the base code works and now it's an issue of finding why the default doesn't let other application consume from IIS / IIS Express.
For reference purpose this is the debug menu in question where the IIS Express option is not working but selecting the project name like pointed out on the picture actually works.
I have a lot of SOAP/XML and REST/JSON experience in Java and C++, but am pretty much a newbie in .NET. I have to create a SOAP client from a WSDL in C# in VS 2012. The app is not a web-based app, but a console app that will be run as a cron job every 24 hours. It has to query a Web Service for a token, do a client database lookup, and then use the token to update a list of client id's on the Web Service with any new ones - two calls only.
The company has a tester where I can type in either SOAP message (envelope and contents) by hand, click the run button, and a window shows the correct response in its SOAP envelope. My only confusion would seem to be endpoint-related. A WSDL-generated client should take care of everything.
I don't know much about C# (5), the .NET framework (4.5.x), or the newer .NET versions of VS (I've been using Eclipse, IntelliJ IDEA, and even jEdit for the past decade and more).
I've seen a dozen different "solutions" to this problem, ranging from WSDL.EXE and SiteUtil.Exe through adding the WSDL file as a (web?) reference or using one of the NuGet addons. The problem is that every solution I've found appears to asssume the client app is built on one of the web templates. I have to do this as a background .exe in plain C# without any web-based support or interaction in my app.
Any suggestions on the best (hopefully simplest) way to generate client source code?
You are not alone in being confused. You have to realize classic SOAP (asmx/wsdl) is considered an "outdated" technology (by Microsoft), so these days it hidden away in the toolset in favor of newer technologies. The most basic approach is to add it as a Reference from the solution explorer within Visual Studio itself. Here is a step-by-step:
Create a console application
In the solution explorer, right-click the References node and choose Add Service Reference
Ignore most of the dialog that comes up, and go straight for Advanced:
From the bottom of the Service Reference Setttings, choose Add Web Reference...
Now fill in the location of your ASMX, hit the little arrow, wait a bit for the tooling to discover the service, then hit Add Reference
This will add a Web Reference to your project that you can then use to access the methods of the webservice.
[Edit] (to answer your question)
If you have a .WSDL file on disk, you simply enter the file location on disk in the URL box of the Add Web Reference dialog:
In that case, the generated service has a default namespace of WebReference (unless you change it, of course), and you'll most likely want to explicitly set the URL:
var service = new WebReference.GlobalWeather {Url = "http://www.webservicex.net/globalweather.asmx"};
var weather = service.GetWeather("Amsterdam", "Netherlands");
Console.WriteLine(weather);
I am using VS 2012 under windows 7x64. I have a winforms application that makes a webservice call to a Java (JBOSS) server. On the client-side I created the connection using Add Service Reference. Everything was generated properly and the communcation between client and my development server works. Now, I would like to point my client at a different server for QA purposes. I researched this and found I should change the app.config, specifically the endpoint address:
<endpoint address="http://devserver01.mydomain.org:80/af-afejb3/TransmitWS_003" ...>
I did this and it seems to work but my question is around other places I may need to change. I did a text search of my entire solution for the old dev server name (devserver01.mydomain.org) and found it still existed in several places including:
configuration.svcinfo,
configuration91.svcinfo,
configuration91.svcinfo,
TransmitWS_003.wsdl,
Reference.svcmap
My thinking is that these files must not matter but I am uncomfortable seeing the old server names within certain files still in my codebase. Are the above files throw-away files that I should not commit to version control? I certainly like the idea of making a simple change to the app.config and this does feel right but I want to be sure. Is the app.config the only place?
thanks
I have a silverlight application consuming data via RIA. Some methods are exposed in a way that they can be consumed in silverlight as well as in WPF application via Service Reference.On development, these services are called via localhost and everything works fine.I have set my hosts file so that it's all available at subdomain.domain.com.
Now (also after a couple of restarts) when I access .svc via different browsers, I get different responses in Chrome and in Internet explorer on the same URL.
Chrome shows:
[Name of] Service,
To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax: ...
You can also access the service description as a single file: ...
Internet explorer, Firefox shows:
[No name displayed] Service,
To test this service, you will need to create a client and use it to call the service. You can do this using the svcutil.exe tool from the command line with the following syntax: ...
the last part (second url, single file access link) is missing in internet explorer.
But the worst part is, if I enter the same url in VS2012 when adding a service reference, I get this message:
The request failed with HTTP status 404: Not Found. Metadata contains a reference that cannot be resolved: ...
How can a service give three different responses to virtually the same request?
Update: Perhaps useful information is also that this service is not contained in a separate .svc file but is a ProjectDomainService.cs (and AuthenticationDomainService.cs) and .svc urls are somehow caught automatically (no such file exists on server).
And, Chrome behaves the same as Internet explorer if I remove
<add name="Soap" type="Microsoft.ServiceModel.DomainServices.Hosting.SoapXmlEndpointFactory, Microsoft.ServiceModel.DomainServices.Hosting, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
from web.config.
Also, pinging subdomain.domain.com shows my local IP as it should.
The problem seems like it was a simple ID-10-T error. Our company has automatic configuration script set for LAN settings under Internet options (connections).
Unchecking this made hosts entries available to all browsers and everything seems to work as expected/desired. While I did know proxies can cause problems when using hosts file, I was unaware of my system settings (it was not set so that it would be visible in settings, but hidden in a configuration file on a network share).
The only browser that worked under these (old) settings was the one that wasn't installed but a portable copy.
As this fixes my problems, I am not sure weather I can expect other unexpected issues now ... but at least it works.
I'm going to use C# to read data from a few webservices. I've done that many times before, but those times I've had direct access to the webservices from my development machine.
In this project I've just been sent a .wsdl file, and a couple of .xsd files for the webservice they have in their local intranet.
I've seen that I can use "Add Web Reference", and point directly to the .wsdl file, so that a C# class is created.
But how can I really test it? I'd like to return some dummy data that I can visualize while I develop. Any tips for this situation?
Mock Webservice
From the above source, a .cs file can be generated by opening a Visual Studio Command Prompt and running something like the following:
wsdl /language:CS /namespace:Your.Namespace.Here
/out:Directory\To\Save\To\ /protocol:SOAP /serverinterface
finally-your-wsdl-file-here.wsdl
You can also try SOAP UI for mocking up service with ease. (Free web service testing tool)
Check:
http://www.soapui.org/gettingstarted/mocking.html
The svcutil.exe tool bundled with the Windows SDK (found at C:\Program Files\Microsoft SDKs\Windows\v6.0\Bin) is a nice command line tool that generates WCF client proxies. I've found this to be a good way to interrogate a WSDL. It'll create an interface for the service and then a proxy class that implements that interface. You can then mock up something else that implements that interface to facilitate testing.
It is easy to create your own server side stub. Assuming you want to do it with WCF, then go here. You can then add some basic logic to get your client working.
You can also use the legacy Web Service functionality via the WSDL tool's /Server option, though I recommend you use WCF.
You may also want to try a product like "Fiddler" (http://www.fiddler2.com)
It allows you to capture HTTP (or HTTPS) packets and send a fake automated reply file back as if the server had sent the response. I use it for my project and it works wonders when the test server goes offline (which is often). I take an old response packet, save it as a text file, then send it back again and the application I'm building has no idea it didn't come from the actual host.
I've also found this article very useful: https://ivangrigoryev.com/en/how-to-mock-a-web-service-in-dot-net/
It describes the steps needed, from downloading the WSDL file and to the creation of the test project:
Get WSDL somehow
In the VS Command Prompt:
wsdl /language:CS /out:C:\Downloads\ /protocol:SOAP /serverinterface C:\Downloads\webservice.wsdl
Create a new ASP .NET Web Application with an empty template
Add the file, generated on step 2, to the project
Add a new service to the project (Add -> New item -> Web Service (ASMX))
Change the class definition in the code for this added web service, so it implements the right interface, e.g replace System.Web.Services.WebService with yours.
Hit Alt+Enter and implement the interface automatically with stubs.
Hit F5, the service will run and your browser will open, copy the URL and use it instead of the real URL.
This works only in .Net Framework since .Net Core and .Net 5 dropped the WCF server support. But I found it acceptable to have the main project on .Net 5, but this mock service on .Net Fw 4.8