Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to understand the analysis of .net integration with other platforms

2025-02-23 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article shows you how to understand the analysis of .net integration other platforms, the content is concise and easy to understand, can definitely brighten your eyes, through the detailed introduction of this article, I hope you can get something.

Integrating distributed applications is often a very difficult and complex task, and even the most experienced developers may have a headache. This integration problem becomes particularly complex when applications are on different operating systems and involve different programming platforms. Although Web service promises can make it easier for programmers to complete integration tasks, they can also cause some unexpected trouble for programmers. Here we will link an ASP.net application with a PHP Web service to learn some ways to integrate distributed applications and the necessary responses, including what to run and what not to do.

This Web service runs on an Apache server and is developed using PHP. It retrieves news summaries and their associated text from various Microsoft newsgroups. Even the data provided by this service can be used directly. Net object access, but the service will still use and provide a connection to the non. A good demonstration on the Net platform. The example we are going to discuss here is based on. Net beta version 2.

Create a Web service proxy

Visual Studio.NET provides an excellent mechanism for automatically generating proxy objects that can be used to access remote Web services. Therefore, first try to use these functions to import the Web Services description language (Web Services Description Language,WSDL) file provided by the PHP service. You can also use the WSDL.exe command line utility of .net SDK. Unfortunately, after importing WSDL using the VS.net wizard, you cannot successfully create an agent. So I have to convert the file generated by VS.Net after importing the original WSDL file into WSDL:

◆ changes the schema domain name space from http://www.w3.org/1999/XMLSchema to http://www.w3.org/2001/XMLSchema and then clears all the "Q" domain name space added by VS.Net during WSDL import.

◆ removes the xmlns:tm= http://microsoft.com/wsdl/mime/textMatching/ and xmlns: mime= "http://schemas.xmlsoap.org/wsdl/mime/" namespaces because these are not needed in this application.

◆ removes the type element because the original WSDL document does not contain the specified element section of the Web service's schema information.

◆ changes the input and output element message attribute value to include the tns domain name space prefix:

The following are quotes: < portType name= "nntpSoapPortType" > < operation name= "getheaders" parameterOrder= "newsgroup numitems" > < input message= "tns:getheaders" / > < output message= "tns:getheadersresponse" / > < operation name= "getarticle" parameterOrder= "newsgroup article" > < input message= "tns:getarticle" / > < output message= "tns:getarticleresponse" / > < / operation > < / portType >

With the following minor changes, the VS.Net wizard can read the WSDL and automatically generate a proxy. After compiling the agent, it is included in an ASP.NET page. However, when the ASP.Net page is executed: "message does not have a correct SOAP root XML tag.", this error is returned from the Web service as a SOAP error.

To accurately evaluate this error, the proxy call is used by a utility called Proxy Trace so that the agent generates the SOAP wrapper. This can be done by adding the following code to the ASP.Net page:

MsNews.Proxy = new System.Net.WebProxy (http://localhost:8080);

After looking at the SOAP wrapper generated by the .net agent, I was a little surprised why this error was returned, because a relative SOAP wrapper was actually generated and sent to the Web service. This error persists even after several attempts have been made to convert it to proxy code. Listing 2 of the code snippet shows the complete SOAP error wrapper returned from the PHP Web service.

After several unsuccessful attempts to connect ASP.Net pages to PHP Web services using proxy objects created in VS.Net, I decided to create a SOAP wrapper from scratch to perform more efficient program debugging. {at first, it looks as if the schema domain name space generated by the .net proxy may be the crux of the problem, because .net uses the 2001 schema specification and the PHP service uses the 1999 version of the specification.

However, I changed the custom SOAP wrapper to version 1999 instead of version 2001, and the error still exists. After trying several other minor changes, I decided to change the domain name space prefix and body element used by the SOAP wrapper from soap (generated by .net proxy) to SOAP-ENV, because I saw the SOAP-ENV prefix returned in the SOAP error message. (see Code 2) this seemingly trivial change solves the problem! When processing any request, the PHP service obviously requires a SOAP-ENV prefix and rejects the request that it does not contain the SOAP-ENV prefix.

Create a custom agent

Now that we understand why the Web service returned a SOAP error, we can create a custom proxy to generate the SOAP wrapper that the web service expects. Although it certainly takes more time to create a custom SOAP wrapper than to use a SOAP wrapper generated by the VS.net or WSDL.exe utility, doing so gives you complete control over the contents of the wrapper. To start creating a custom agent, I create a new class called msnewsserviceproxy that contains two fields:

The following is the quoted content: public class MSNewsServiceProxy {string _ uri;string _ soapAction;}

The uri field holds the location of the Web service, while the _ soapAction field holds the name of the SOAPAction header to be sent using the SOAP wrapper. Within the MSNewsServiceProxy class, add three methods: CreateSoapEnvelope (), SendSoapEnvelope () and FilterResult (). These methods generate a SOAP wrapper request, send it to the Web service, and then filter the returned SOAP wrapper. Let's look at each method one by one. Notice that the code adds a SOAP-ENV domain name space prefix to the root element of the SOAP wrapper. The Web service obviously requires this particular prefix and rejects any information that does not contain this prefix. Because the agent generated by VS.net sends a soap domain name space prefix (instead of SOAP-ENV), its message is rejected. Web services should not require a specific domain name space prefix to reject messages without a prefix, but domain name space issues also mean that you have to pay attention to doing things that don't seem {0 > imaginable in order to get the job done better.

After the SOAP wrapper is created, the SendSoapEnvelope () method (see snippet 4) uses several classes in the System.Net and System.IO domain space to send the wrapper to the Web service. The code first creates a HttpWebRequest object by passing the _ uri variable to the object constructor. Second, the corresponding Method,ContentType and Header associated with the request will be sent.

A StreamWriter object is then associated with the request flow of the HttpWebRequest object, and the SOAP wrapper is written to the stream using the Write () method of StreamWriter.

The SOAP wrapper returned from the Web service is obtained by the SendSoapEnvelope () method of the HttpWebResponse object.

HttpWebResponse response = (HttpWebResponse) request.GetResponse ()

If the reply is not null, it will be loaded into a XMLTextReader,XMLTextReader that is used to populate the XmlDocument object. Then the XmlDocument object is returned from this method.

The FilterSoapEnvelope () method parses the SOAP reply wrapper and loads the data returned from the Web service into the XmlDocument object used by the consumer of the custom proxy:

The following are references: private XmlDocument FilterSoapEnvelope (XmlDocument doc) {XmlDocument filterDoc = new XmlDocument (); XmlNode result = doc.SelectSingleNode ("/ / results"); XmlNode resultImport = filterDoc.ImportNode (result,true); filterDoc.AppendChild (resultImport); return filterDoc;}

Although the filter can be executed in several ways, the FilterSoapEnvelope () method relies on the XPath statement to get the result elements in the reply SOAP wrapper.

The Microsoft newsgroup PHP Web service shows two ways to allow you to get a newsgroup summary: getheaders () and getmessage (). You can see how to use these two methods in custom proxy classes (see code snippet 5). Notice that the code in each method passes the Web service method name to the CreateSoapEnvelope () method and any parameters associated with it. After the SOAP wrapper is sent and the reply is accepted, the FilterSoapEnvelope () method is called to load the returned data into a XmlDocument object, which is also used by the proxy "consumer".

The above content is how to understand. Net integration analysis of other platforms, have you learned the knowledge or skills? If you want to learn more skills or enrich your knowledge reserve, you are welcome to follow the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report