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 { ... });
Related
I'm creating a .Net application to consume the Soap APIs.
I downloaded 2 partner wsdl files from 2 instances(production and sandbox). I think the only difference of the two APIs are their endpoints.
I then added the web references to a single application. When I write the method to consume the APIs, I don't want to duplicate the code to do same thing(insert,update...).
How can I design my code so maybe I can pass a parameter to let the method know which target instance should it talk to?
Thank you!
If the services are truly the same and just the endpoint differs, you should be able to use the generated client's Endpoint property to change the endpoint.
var client = new ServiceReference1.WebService1SoapClient();
client.Endpoint.Address = new System.ServiceModel.EndpointAddress("http://localhost:2850/WebService1.asmx");
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?
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.
Scenario:
I am using Silverlight 3.0 as client for a web service.
Design:
The server has a class named DeviceInfoService which has the basic functionality of getting the list of devices, getting the properties of devices etc.
When I open an ASP.NET project and try to add a web reference, I can find an option to add a "Web Reference". After I add the web reference this way, I am able to access the DeviceInfoService class by creating it's object and then accessing it's methods.
Web Reference v/s Service Reference:
Coming to Silverlight: when I try to add a service reference, there is no option to add a web reference. Going with Service Reference, everything works fine till WSDL file is downloaded. People say that I can get this option by going back to .NET 2.0, but probably Silverlight won't work in .NET 2.0
The Problem
Now when I try to access the class DeviceInfoService , I am not able to find it. All I get is Interfaces -- DeviceInfoServiceSoap and DeviceInfoServiceSoapChannel. Classes named DeviceInfoServiceSoapClient.
The methods GetHostedDevices and GetDeviceInfo are no longer available. All I get is GetDeviceInfoRequest, GetDeviceInfoRequestBody, GetDeviceInfoResponse and GetDeviceInfoResponseBody.
I googled a lot how to use these four classes, only to find nothing. I want to get those 2 classes directly like in ASP.NET and not using those Request Response type.
You sound awfully confuse about some concepts.
How about you watch the following Silverlight.Net video and see if that helps?
How to Consume WCF and ASP.NET Web Services in Silverlight
What is web reference in ASP.NET is equivalent to service reference in Silverlight.
Here's an example of how to use a web service in Silverlight, e.g. the CDYNE Profanity Filter.
Add a new Service Reference to your project, URL is: http://ws.cdyne.com/ProfanityWS/Profanity.asmx?wsdl, leave the name as ServiceReference1.
Use this code behind to call the service (which was implemented to be asynchronous):
public MainPage()
{
InitializeComponent();
string badText = "I wonder if the filter will filter this out: shit bad luck";
ServiceReference1.ProfanitySoapClient client = new ServiceReference1.ProfanitySoapClient();
client.ProfanityFilterCompleted += new EventHandler<ServiceReference1.ProfanityFilterCompletedEventArgs>(client_ProfanityFilterCompleted);
client.ProfanityFilterAsync(badText, 0, false);
}
void client_ProfanityFilterCompleted(object sender, ServiceReference1.ProfanityFilterCompletedEventArgs e)
{
string cleanText = e.Result.CleanText; // Web service callback is here
}
And you've got a web service up and running in Silverlight!