I got a project with the same behavior, a Web Service (asmx) was behind a VPN and they use username/password to access it, but inside the VPN it was ok.
It will be hard to generate the proxy class directly from Visual Studio (maybe lack of support for such scenarios) but the trick is really easy as long as you can see the schema in a browser (the wsdl part).
do this:
- open the
?wsdl
link in a browser, go toSource Code
mode and copy the entire code to a file in your local computer, let'a assumec:\temp
and calledservice.wsdl
- copy
svcutil.exe
toc:\temp
(it's in .NET Framework folder, just search for it) - open a terminal in
c:\temp
(Shift + Right Click inside the folder and choose Open command window here) - run the following command:
svcutil service.wsdl /out:proxy.cs /config:proxy.config
This will generate 2 files, the proxy.cs
and the proxy.config
proxy.cs
is your web service wrapper, all you need is to add to your projectproxy.config
has the<system.serviceModel>
that you need to append to yourweb.config
file.
Now, all you need to do is follow the generated wrapper and write something like:
// Web Service initialization and authentication
client = new MyNamespace.ServiceSoapClient();
client.ClientCredentials.UserName.UserName = cUser;
client.ClientCredentials.UserName.Password = cPass;
// do something
client.InsertCompetitor(model);
// close connection
if (client != null && client.State == System.ServiceModel.CommunicationState.Opened)
client.Close();