. NET calls to external WebService interfaces

Source: Internet
Author: User

Requirements: Before doing this project need to use a Java WebService interface, the first thought of the first method is to add a service reference. But then there will be a config file generated DLL must read config file, config file in the same directory is not , it needs to be placed in another tool's node to be read by another tool, unfortunately another tool cannot add a node no one will boom

Second: The next step is only handwritten address in the program inside. Then I searched the article in Baidu. The code does not have an accidental paste copy, and then write your own C # webserive test completely no problem. It's not going to work when it's discovered to Java. The solution, the error can not find the name space, and so on.

Three: WCF provides it. First, a factory method and a proxy class are required. Proxy classes can be generated with WCF tools, as follows Http://blog.163.com/[email protected]/blog/static/3743053820132133616282/ Quote someone else, just do it. This is the original address. At this point, we get a proxy class, and then find a factory method

 Public StaticT createservicebyurl<t> (stringURL) {returnCreateservicebyurl<t> (URL,"BasicHttpBinding");} Public StaticT createservicebyurl<t> (stringUrlstringBing) {Try{if(string. IsNullOrEmpty (URL))Throw NewNotSupportedException ("This URL was not Null or empty!"); EndpointAddress Address=Newendpointaddress (URL); Binding binding=createbinding (Bing); ChannelFactory<T> factory =NewChannelfactory<t>(binding, address);returnFactory. CreateChannel ();}Catch(Exception ex) {Throw NewException ("An exception occurred while creating the service factory.");}}#endregion#regionCreate a transport protocol/// <summary>///Create a transport protocol/// </summary>/// <param name= "binding" >Transport protocol name</param>/// <returns></returns>Private StaticBinding createbinding (stringbinding) {Binding bindinginstance=NULL;if(Binding. ToLower () = ="BasicHttpBinding") {basichttpbinding ws=Newbasichttpbinding (); ws. MaxBufferSize=2147483647; ws. Maxbufferpoolsize=2147483647; ws. MaxReceivedMessageSize=2147483647; ws. Closetimeout=NewTimeSpan (0, -,0); ws. Opentimeout=NewTimeSpan (0, -,0); ws. ReceiveTimeout=NewTimeSpan (0, -,0); ws. Sendtimeout=NewTimeSpan (0, -,0); Bindinginstance=ws;}Else if(Binding. ToLower () = ="nettcpbinding") {nettcpbinding ws=Newnettcpbinding (); ws. MaxReceivedMessageSize=65535000; ws. Security.mode=securitymode.none;bindinginstance=ws;}Else if(Binding. ToLower () = ="Wshttpbinding") {wshttpbinding ws=NewWshttpbinding (securitymode.none); ws. MaxReceivedMessageSize=65535000; ws. Security.Message.ClientCredentialType=System.servicemodel.messagecredentialtype.windows;ws. Security.Transport.ClientCredentialType=system.servicemodel.httpclientcredentialtype.windows;bindinginstance=ws;}returnbindinginstance;}
View Code

And then here's the code that's used.

String url = "Fill in your interface address here";

Client-generated interface names such as public interface AA are written like this

AA a=wcfinvokefactory.createservicebyurl<aa> (URL);

A. Method (the "parameter") is required to invoke the parameter in the new proxy class;

. NET calls to external WebService interfaces

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.