How to use FedEx Web Services in flutter - web-services

I'm developing an APP to track FedEx packages using flutter. Where should I integrate FedEx web service WSDL into my code so that I can send my tracking request to FedEx and get the response back?
Currently I'm testing with another api and able to get response by sending request directly to the url of this api. But FedEx web service does not work that way and I have to use their WSDL to set the url.
Beer.fromJSON(Map<String, dynamic> jsonMap) :
id = jsonMap['id'],
name = jsonMap['name'],
tagline = jsonMap['tagline'],
description = jsonMap['description'],
image_url = jsonMap['image_url'];
}
Future<Stream<Beer>> getBeers() async {
final String url = 'https://api.punkapi.com/v2/beers';
final client = new http.Client();
final streamedRest = await client.send(
http.Request('get', Uri.parse(url))
);
return streamedRest.stream
.transform(utf8.decoder)
.transform(json.decoder)
.expand((data) => (data as List))
.map((data) => Beer.fromJSON(data));
}

WSDL isn't something you import into your app, or at least not with dart. It describes the requests that can be made to the various endpoints their server supports.
Fedex's documentation does a better job explaining than I could:
A SOAP request to, or response from a service is generated according to the service’s WSDL definition.
A WSDL is an XML document that provides information about what the service does, the methods that are available, their parameters, and parameter types. It describes how to communicate with the service in order to generate a request to, or decipher a response from, the service.
The purpose of a WSDL is to completely describe a web service to a client. A WSDL generally defines where the service is available and which communication protocol is used to talk to the service. It defines everything required to write a program that will work with an XML web service.
There's a good chance that the endpoint actually uses SOAP for the communication, which dart doesn't currently fully support. You're going to have to use something like dart:xml to generate requests that match the description in the WSDL, and then you can send them with the http.Client the same way as you have done for the other API.

Related

Apache CXF And javax.ws.rs.core.Response

i have a methode deleteProduct:
#Override
public Response deleteProduct(String productId) {
Response response = Response
.status(Response.Status.FORBIDDEN)
.entity(new IllegalAccessError("This is a JAXB object with an error string"))
.build();
return response;
}
my problem is always i get this response :
<ns2:deleteProductResponse xmlns:ns2="http://ws.cxf.test.com/">
<return/>
</ns2:deleteProductResponse>
why i dont see my message error ?
I think you are getting confused between JAX-RS and JAX-WS . If this is SOAP-UI you are referring to, it means you are building SOAP based web services or, in other words are using SOA - service oriented architecture which works on the SOAP protocol and not HTTP. Hence HTTP Status codes or error messages based on them do not come into picture here.
However, if you are building a RESTful web service (one that is based on JAX-RS), it has everything to do with HTTP.
First, decide what framework to use based on your project requirements and then code accordingly.

Soap Client consuming Rest Web Services

I am working on this project where the client only supports SOAP WSDL for consuming web services where as it supports rest for incoming calls. I need to Integrate this tool with another tool which is completely restful(has WADL). Is is possible for soap client to consume restful web services? If yes which tool will you all suggest?
No, it's not possible for a soap client to consume restful services. There is no interoperability between them whatsoever.
Even if you could do this you should not. Use a tooling library and just create a rest client for your rest service.
SOAP defines a standard communication protocol (set of rules) specification for XML-based message exchange. SOAP uses different transport protocols, such as HTTP and SMTP. The standard protocol HTTP makes it easier for SOAP model to tunnel across firewalls and proxies without any modifications to the SOAP protocol.
REST describes a set of architectural principles by which data can be transmitted over a standardized interface (such as HTTP). REST does not contain an additional messaging layer and focuses on design rules for creating stateless services. A client can access the resource using the unique URI and a representation of the resource is returned. With each new resource representation, the client is said to transfer state. While accessing RESTful resources with HTTP protocol, the URL of the resource serves as the resource identifier and GET, PUT, DELETE, POST and HEAD are the standard HTTP operations to be performed on that resource.
It can be done via jQuery.
jQuery sample for the Language Identifier :
$.post('https://services.open.xerox.com/RestOp/LanguageIdentifier/GetLanguageForString',
{'document' : 'This is a sample'}, function (data) {
var res = 'Not found';
if (data != null) {
res = data;
}
});
Further reading: https://spring.io/guides/gs/consuming-rest-jquery/

Remote Web service

I am new to web services. I have a requirement in my project. They gave me a wsdl file and a web service link and document about the description of methods.
In the documentation there is method called retriveDocuments with request parameters request, loginUser, loginPassword, systemId, maxResults, searchCriteria.
They want me call webservice and get the required documents and show them in app.
My question is how do I call web service and how do I pass all these parameters and get the result?
Most likely this a SOAP service. Your programming language (such as Java) should have tools allowing you to generate a SOAP client for the service, using the WSDL. Once you have the cient code, it should be easy to pass your parameters, make the call, and get the result. There are lots of tutorials on the Web, but you can start researching from there.

Automatically pass a cookie with each web-service call

I have a standalone web-service client. When invoking any of the web-methods an additional "cookie" string must be implicitly(not as a web-method parameter) passed to the WS. The WS on the other end must be able to obtain the string and use it. How can this be achieved?
I invoke the service in the following way:
Service srv = Service.create(new URL(WSDL), QNAME);
myClassPort = srv.getPort(MyClass.class);
What I need is to put some code before the first line, which would make the client send this "cookie" string every time I invoke some remote method via myClassPort. Thx.
By default JAX-WS web services and clients are stateless. When a client makes a request, the server responds and sets a cookie on the connection, if it participates in a session. But, the JAX-WS client ignores that cookie and the server treats subsequent requests as new interaction. When the session is enabled, JAX-WS client sends the same cookie with each subsequent request so that server can keep track of the client session.
So you should not be using either cookies or HTTP sessions with web services. Return a token ID as part of the response; then the client can send that along with the next request.
Anyway:
JAX-WS web service clients must be configured to maintain session information (such as cookies), using the javax.xml.ws.session.maintain property.
Other web service stacks may have similar mechanisms.
On the Server Side
JAX-WS uses some handy annotations defined by Common Annotations for the Java Platform (JSR 250), to inject the web service context and declaring lifecycle methods.
WebServiceContext holds the context information pertaining to a request being served.
You don't need to implement javax.xml.rpc.server.ServiceLifecycle. With JAX-WS Web Service all you need to do is mark a field or method with #Resource. The type element MUST be either java.lang.Object or javax.xml.ws.WebServiceContext.
#WebService
public class HelloWorld {
#Resource
private WebServiceContext wsContext;
public void sayHello(){
MessageContext mc = wsContext.getMessageContext();
HttpSession session = ((javax.servlet.http.HttpServletRequest)mc.get(MessageContext.SERVLET_REQUEST)).getSession();
}
}
There are some misleading answers to this question, so I will attempt to highlight current best practices. Most of these suggestions are part of the OWASP security guidelines, which I strongly recommend anyone working on web development to review.
1) ALWAYS use temporary (session scoped) cookies.
2) All cookies should be protected and encrypted.
3) Do not pass tokens in request payloads
4) For any requests which return data that may be sent back to the server, include a nonce (single use token) in your responses.
5) later requests should (must) include the nonce and the cookie
Again, my recommendation is to review the OWASP guidelines and proceed accordingly.
You may want to look into using a service provider for authentication - this is much smarter than brewing your own solution as there are literally a million details that all must be correct. Auth0.com is one of these.

WS security Coldfusion

Working on a docuSign integration with Coldfusion and need assistance in making the SOAP request using WS security.
Your question is a little short on detail, but I presume you mean the Web Services SOAP security extension.
We had to do this a few years back when communicating with a .NET web service. The basic idea is that you provide a set of extra SOAP headers that contains security info such as:
Timestamp
Username
Password
Etc
To do this you need to create a new XML document as per the standard defined here. Next you will need to write code to create the SOAP headers. This means:
Create your remote web service object, e.g.
var objWebSvc = createObject("webservice", "http://remoteURL?WSDL");
Creating an XML document to represent the new headers
Populating it with the required info (such as username and timestamp etc.)
Adding the XML document to the web service object, using addSOAPRequestHeader()
Call your remote web service
Then of course if and when they call your web service you'll need to parse out those headers from their SOAP request and validate them. That can be done by grabbing the XML using getSOAPRequestHeader() and parsing out the info.
I found this to be an error prone task and (basically) a royal pain. The web service we integrated with eventually dropped the requirement, apparently becuase the any web services trying to connect that were not native .NET were having a hard time implementing the specification.
Good luck!
I blogged this a while back. See if this helps:
http://onlineanthony.blogspot.com/2010/05/using-ws-security-for-soap-in.html