adding a service reference in VS 2012 without an endpoint WSDL - web-services

I need to add a service reference to our 3rd party's web service but I'm told they do not host the endpoint wsdl. I do however have a local copy of the wsdl so can anyone give me any pointer as to the best way to do this?
thanks

To access 3rd party web service using a wcf client you have to:
1.) Create service reference from wsdl file. See How to generate service reference with only physical wsdl file
2.) Instantiate the WCF client and call the required method. Sample code:
// Create a client object. CalculatorClient class was generated in service reference code.
CalculatorClient calcClient = new CalculatorClient();
// Call the Add service operation.
double value1 = 100.00D;
double value2 = 15.99D;
double result = calcClient.Add(value1, value2);
Console.WriteLine("Add({0},{1}) = {2}", value1, value2, result);
For more see Instantiate the WCF client proxy section in Accessing Services Using a WCF Client

Related

"Object reference not set to an instance of an object" When adding new WCF Service

When trying to add a new WCF Service to an existing project in Visual Studio 2019, I get the error "Object reference not set to an instance of an object", and the svc files does not get added to the project. For example, if the file I try to add is "Service.svc", the file "IService.cs" will be added, but not "Service.svc". Has anyone encountered something like this and know how to resolve it?
By adding service will generate a client proxy containing the service interface, instead of a service implemented class. afterward, we could call the WCF service by means of a client proxy as like calling a local method.
ServiceReference1.ServiceClient client = new ServiceClient();
var result = client.Test();
Console.WriteLine(result);
The Url in the Adding Service Reference dialog is the service metadata address.
http://vabqia969vm:8818/Service1.svc
Alternatively, it could be the Mex endpoint when the WCF service is self-hosted.
https://vabqia969vm:21011/mex
Please refer to the below official documentation.
https://learn.microsoft.com/en-us/dotnet/framework/wcf/accessing-services-using-a-wcf-client
https://learn.microsoft.com/en-us/dotnet/core/additional-tools/wcf-web-service-reference-guide
Feel free to let me know if the problem still exists.

Axis2 multiple connection authentication issue

I have two servlets that access two corresponding Axis2 web services on the same host. One of the servlets is read-only, while the other writes to a database.
Each of the Axis2 web services uses BASIC authentication. The read-only web service uses a system account, while the write web service uses the user's credentials (which are submitted as part of a web form).
The problem I'm running into is that the servlet called second always fails authentication to its web service. For example, I can query the read-only service through it's servlet all I want, but I get a "401: Authorization Required" when I try to use the write service. If I call the write service first, I get the same error when I try to use the read-only service.
Here is how I am setting the credentials for the connections in the servlets:
Stub service = new Stub(serviceUrl);
HttpTransportProperties.Authenticator auth = new HttpTransportProperties.Authenticator();
auth.setUsername(username);
auth.setPassword(password);
auth.setPreemptiveAuthentication(true);
service._getServiceClient().getOptions().setProperty(HTTPConstants.AUTHENTICATE, auth);
The servlet that accesses the read-only service has this code in it's constructor. The servlet that accesses the write service has this code in it's doGet/doPost method.
It seems that the credentials for the first service called are getting cached somewhere, but I can't find where that could be. I saw a possible solution here, but I can't find where WSClientConstants.CACHED_HTTP_STATE is defined. The comments in this JIRA issue seems to imply that it's part of org.apache.axis2.transport.http.HTTPConstants but it's not there.
Specifics:
Axis version: 1.5.1
Tomcat Version: 6.0.26
Java version: 1.6.0_23
It turns out the connections to the two different services were using the same JSESSIONID. Thus, the connection to the second web service was trying to use a session authenticated for the first web service, causing the error.
My solution for this was to define an HttpClient for each service, done by the following
MultiThreadedHttpConnectionManager manager = new MuliThreadedHttpConnectionManager();
HttpClient client = new HttpClient(manager);
ConfigurationContext context = ConfigurationContextFactory.createDefaultConfigurationContext();
context.setProperty(HTTPConstants.CACHED_HTTP_CLIENT, client);
context.setProperty(HTTPConstants.REUSE_HTTP_CLIENT, true);
Stub service = new Stub(context, serviceUrl);
This allows both servlets to have a separate session for their corresponding services.
The important point is to create a dedicated ConfigurationContext.
I've solved in a simpler way using a default config context when creating the stub without the multithreaded connection factory
stub = new MyStub(ConfigurationContextFactory.createDefaultConfigurationContext(), myServicesUrl);

BizTalk web service to return a value rather than void + ref

Is there anyway to get the web service generated by the BizTalk Web Services Wizard for an orchestration to return a value, rather than it have a void return and it use return by ref ?
I'm trying to emulate an existing web service which is very simple ... the web method takes a string and returns a string ... public string MyTestMethod(string MyVal)
The proxy to the web service from the orchestration works, but the BizTalk wizard generates ... public void MyTestMethod (ref string MyVal)
I've tried the Advanced option, Force Request Response, but that doesn't seem to do anything
Are you trying to publish an Orchestration as a web service or Schema as a service?
Considerations while using the web service wizard : http://technet.microsoft.com/en-us/library/aa559660(BTS.20).aspx ... for 2006 R2
The only answer I found was to manually edit the ASMX.CS file that the BizTalk Web Service Publishing Wizard generates ...
Change the ElementName on the methods in parameter ... ([XmlElement(Namespace = null, ElementName = "XML")] string part)
Completely remove the ... [return: System.Xml.Serialization.XmlElementAttribute ...] attribute
Plus adjust the WebService(Name="", Namespace="",...) values to suit
This of course means that you can't just re-generate with the Wizard :-(
I know it's a quite old post, but just in case some else comes to it: I managed to do it as suggested by Tom Redfern above. It works perfectly if your inbound orchestration port is two-way.
In my case I had to expose an orchestration as WCF service where my orchestration receives a domain (e.g. "gmail.com") as input parameter, does some processing and at the end executes a stored procedure that fetches a list of e-mails belonging to that domain. So I had a "Domain" as input and "ListOfUsers" as output. Having my inbound orchestration port as "TWO-WAY" allowed me to receive a message of type "Domain" and output message of type "ListOfUsers".
Afterwards I could use "BizTalk WCF Service Publishing Wizard" and it generates it perfectly. Just had to adjust namespaces, port names, application pool and etc. and all good! Tried using SoapUI and works brilliant!

gsoap: how to make it configurable?

I've implemented client for my Web Service. Auto-generated files for each web method contain hardcoded bindings to web service end point:
soap_endpoint = "http://localhost/MyService.asmx";
It is fine for development purposes, but before pushing that to PROD I will need to replace those string with PROD web service address.
Is it possible to manage gSOAP in order it generated this string to be putted in some 'external' variable?
Or I should replace those end-point value each time before deployment?
Thanks.
The functions generated from the gSoap Compiler are looking like:
soap_call_ns1__foo(struct soap* soap, char *URL, char *action, char *symbol, resultType &Result);
The argument URL is the endpoint adress. If you pass NULL, the endpoint from the WSDL file is used. But your client can call this function with any other endpoint -- which for example is defined within your clients configuration file.
If your client is using the -- from the gSoap compiler generated -- proxy class, it is also possible to set the endpoint. The proxy class has a member called endpoint which you can set before calling the service methods.
In the gSoap compiler generated ***proxy.h header file you will find
"endpoint = "http://localhost/MyService" in the class constructor.
Replace "localhost" with the "IP-address" of your web-service before pushing it to PROD.

J2me web service connection problem

i'm trying to connect to a php web service using kxml-rpc api and the code is as simple as this:
XmlRpcClient xmlrpc = new XmlRpcClient("http://***ip here***:88/secure/service");
Vector parameters = new Vector();
parameters.addElement("value");
String result = (String) (xmlrpc.execute("functionName", parameters));
Mobile device asks for permission to connect to GPS. But somehow the result is always null.
What can be done? and what configuration i should check?
Thanks.
Check whether the web service provider is actually invoked, and what does it return. It is not unlikely that it returns null, (so the clients gets it).