C # Method of adding SHENFA authentication information when calling Java WebService

Source: Internet
Author: User

Java-generated webservice requires that Authorization:basic xxxxxxxxxxxxxxx authentication information be brought in the header of HTTP at the time of invocation

Since the service is called directly after adding the Web reference, rewrite the service class, overriding the GetWebRequest method of the service class, as shown in the example code

public class Myservice:xxx service class {public myservice (string url) {        url = URL; } protected override WebRequest GetWebRequest (Uri uri) {HttpWebRequest request = (HttpWebRequest ) base.            GetWebRequest (URI); if (preauthenticate)///use, you must set the PreAuthenticate property of the service class to true and set the credentials property {NetworkCredential Net Workcredential = base.                Credentials.getcredential (URI, "Basic"); if (networkcredential! = null) {byte[] Credentialbuffer = new UTF8Encoding (). GetBytes (NetworkCredential. UserName + ":" + networkcredential.                    Password); Request.                headers["Authorization"] = "Basic" + convert.tobase64string (Credentialbuffer);            } else throw new ApplicationException ("No Network Credentials");        } return request; }} 

Reference information:

http://stackoverflow.com/questions/20495105/basic-authentication-in-php-webservice-with-c/20517700#20517700

http://stackoverflow.com/questions/897782/ how-to-add-custom-http-header-for-c-sharp-web-service-client-consuming-axis-1-4/1712795#1712795

C # Method of adding SHENFA authentication information when calling Java WebService

Related Article

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.