How do I consume this SOAP web service? how do I add the request header?
https://www.eway.com.au/gateway/ManagedPaymentService/test/managedCreditCardPayment.asmx?op=CreateCustomer
REF: http://www.eway.com.au/Developer/eway-api/token-payments.aspx
The easiest way is to use .NET's built-in support.
In Visual Studio, right click on your project references and 'Add Service Reference'. Give it the service URL https://www.eway.com.au/gateway/ManagedPaymentService/managedCreditCardPayment.asmx and it will generate a proxy class for you that will do all the work. You can then just e.g.
var client = new eWayServiceReference.managedCreditCardPaymentSoapClient();
client.CreateCustomer(...);
Alternatively you can generate the proxy class from a VS command prompt using svcutil.
Related
I'm having trouble understanding how to consume an existing ServiceStack based web service (https://cert.web.transaction.transactionexpress.com/TransFirst.Transaction.Web/api/). I am using a standard vstudio .net 4.6 aspnet website c# form.
I tried adding the base service uri as a service reference to my existing project (Website > Add Service Reference > URI) but on building my solution I receive error: [Error: failed to generate code for the service reference. Cannot import wsdl:portType...].
I would like to think that I can interact with this service without manually building object definitions, so I must be missing a step.
Two questions:
1. Has anyone else worked with this particular service? Or can you suggest how to generate object definitions from this service?
2. Am I incorrectly assuming that generating the object definitions will give me full VStudio intellisense on my httpclient?
Since this is a ServiceStack Web Service you can use C# Add ServiceStack Reference to generate a Typed API in C# which you can use with ServiceStack's C# Service Clients.
The BaseUrl for this Service is:
https://cert.web.transaction.transactionexpress.com/TransFirst.Transaction.Web/api/
So if you install ServiceStack VS from VS.NET Extension gallery:
You can create a Typed C# API by clicking on Add ServiceStack Reference on your project:
Then you can use the Typed DTOs with ServiceStack's generic Service Clients, e.g:
var baseUrl = "https://cert.web.transaction.transactionexpress.com/TransFirst.Transaction.Web/api/";
var client = new JsonServiceClient(baseUrl);
var response = client.Post(new CreateCustomReport { ... });
Different from the last command in doc https://learn.microsoft.com/en-us/dotnet/framework/wcf/how-to-create-a-wcf-client, the program hints me to use 'svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config http://localhost:8000/ServiceModelSamples/service?wsdl' to generate client proxy code and the config file when I follow the tutorial exactly.
So I have two questions.
Does base address must start with 'http://'? Just like what is shown in https://learn.microsoft.com/en-us/dotnet/framework/wcf/how-to-host-and-run-a-basic-wcf-service. Can I use some other kind of base address if I don't use http binding?
If the answer to #1 is yes, what will the command be? It's better if you can give me an example.
Yes the base address must start with http or https because it needs to be hosted on a web server (like IIS). If you have done that you need to create a service reference to your project via: right click "Connected Services" --> add "Service reference" then type in your address choose your .svc file --> choose a name (e.g. ServiceRef) and click ok..
Then add your proxy to execute methods from the service like:
ServiceRef.ServiceRefClient proxy = new ServiceRef.ServiceRefClient();
bool testresult = proxy.TestConnection();
I am consuming odata service using DataServiceContext and want to return data in json format.
I am looking something like this:
Odata Query with DataServiceContext and get result as json
If I try to add any request header in the sending request event. I can't see that header in fiddler. Although the event is firing which I have confirmed.
I came across "context.Format.usejson" and try to search it but didn't find anything which I can understand. Can somebody help me please ?
Using ODataLib to call a WCF Data Services service operation and JSON
My goal is to consume to OData Service and get result in JSON format using DataServiceContext.
Note: These steps only work if max protocol version of your service is 3 or higher. Version 3 of OData introduced a new JSON format, and the WCF Data Services client only supports this JSON format. (Old JSON payloads have things like "__metadata" at the top and "d":{...}. In the new JSON format, you'll see things like "odata.metadata", "odata.type", etc.)
First, make sure you have version 5.1 or greater of the WCF Data Sevrices client library (Visual Studio ships with an older version) and an updated version of the tooling that makes "Add Service Reference" in Visual Studio work.
You can download the latest tools installer here: http://www.microsoft.com/en-us/download/details.aspx?id=35840.
Once you've installed that, I recommend upgrading to the latest version of the WCF Data Services client by issuing the following command in the NuGet package manager console:
Install-Package Microsoft.Data.Services.Client
Once you've upgraded to the latest client library, you should be able to use JSON in the client without a problem. Right click on your project in Visual Studio, select "Add Service Reference" and enter the URL of the metadata document of the service. In v5.1 and above, this will pull down the full model of the service, which is needed to support JSON.
"Add Service Reference" will auto-generate a subclass of DataServiceContext. (You can see this generated code by selecting "Show All Files" in the solution explorer of Visual Studio and expanding the code behind the service reference.) For example, when I do "Add Service Reference" against http://services.odata.org/V3/OData/OData.svc/$metadata, the client library generates a class called DemoService. Use that derived class instead of DataServiceContext directly, and you can just call .Format.UseJson(). For example:
var context = new DemoService(new Uri("http://services.odata.org/V3/OData/OData.svc");
context.Format.UseJson();
You can call context.Format.UseJson method without providing a parameter if you load your service model inside OnContextCreated partial method as shown in the code below:
public partial class DemoService
{
partial void OnContextCreated()
{
this.Format.LoadServiceModel = GeneratedEdmModel.GetInstance;
}
}
I've been tasked with creating a class wrapper for a SOAP service, the idea is that you'll be able to treat it as a regular class. The main reason for this is that the WDSL for the SOAP service contains only one method and it's got 5 parameters and it's only kind of OO so you'd have to know all the method calls really well and it's a bit hard to remember them all.
OK, so I've tried adding a web reference, now web references can now be added as service references in VS 2010. You click add service reference advanced etc and it puts in a service reference. Great. Unfortunately if I try and access this from a class I can't.
I can build a console app and put code in the main procedure and access the method of the SOAP service fine but when I add a reference to a class library the intellisense won't allow me to select anything. I'd instantiate an instance like so:
SOAPService.webServiceService ws = new SOAPService.webserviceService();
ws.
and then the intellisense refuses to kick in. If I do the same in a web project or a console app then I can access it fine. I've added the namespace I've done all kinds of things. Also, I can add a web reference and get a DISCO file whenever I create a web project.
OK, also while I'm on the subject I also need to pass credentials to the web service in PHP.
The problem is that in the past I'd create some .net system credentials and add these and it would usually pass through if I was connecting to another .net service.
How should I be sending them to a PHP web service? I always get either invalid username/password combo errors or envelope malformatted error types
Thanks
Mr. B
So the intellisense is not working, but if you add the method in and try to use it does it work, or produce an error?
With regard to diagnosing authentication issues try using fiddler to view the SOAP messages that are being sent, and to view the reply. Do you have some other software that connects and authenticates to that service? Use fiddler to look at the SOAP messages and compare them to see if the header is different etc.
I'd normally do it like this,
using (Service service = new Service())
{
service.ClientCredentials.Windows.ClientCredential.Domain = "domain";
service.ClientCredentials.Windows.ClientCredential.Password = "password";
service.ClientCredentials.Windows.ClientCredential.UserName = "username";
}
Also with regard to the service working or not in general use fiddler if you have any problems, you can see the SOAP messages and it often gives you a clearer message.
I know in IIS you can turn on failed request handling that also gives you an insight from what is going on at the server end, perhaps you have some form of logging too for your php service?
I am using Visual Studio 2008 and have added a web reference that points to a WCF web service.
Visual Studio has generated a client class automatically, so all I need to do to call the web service is to create an instance of the client and call the method on it.
FoodPreferenceServiceClient client = new FoodPreferenceServiceClient();
FoodPreferenceServiceResponse = client.GetFoodPreference();
The FoodPreferenceServiceClient is the web service client that is automatically generated by VS.
The GetFoodPreference is the method on the web service that I am calling.
My problem is that I want to expose the actual HTTP header received in the above call,
such as client.GetHttpResponse() or something.
Is there a way to do this?
Yes it should be possible. Try:
using (var scope = new OperationContextScope())
{
var client = new FoodPreferenceServiceClient();
response = client.GetFoodPreference();
var httpProperties = (HttpResponseMessageProperty)OperationContext.Current
.IncomingMessageProperties[HttpResponseMessageProperty.Name];
var headers = httpProperties.Headers;
// Now you should be able to work with WebHeaderCollection and find the header you need
}
you can't get the message headers through OeprationContext directly in client side, but you can develop a custom IClientMessageInspector, and in the interface you can get he SOAP XML message.