I. background
Recently, the company launched a PLM system named PTC in the United States. Because the internal business and other aspects need to achieve data interaction between the PLM system and other original systems. Currently, the solution officially provided by PLM is to import and export data through Excel for Data Interaction. However, this solution is rejected in terms of timeliness, efficiency, and convenience. Initially, I planned to use WebService to build WebService in flexplm, but the official team responded that all their secondary development has never used WebService, so it is difficult to implement it. Finally, I finally proposed a third solution. I submitted data through the HTTP protocol and called the API to exchange data.
Someone may ask why not to directly operate the database? Amount ...... For a database system with 18 tables involved in an operation, it is quite difficult to parse it. You can still use the API. Although it seems like a lot of twists and turns, there is no way to achieve it, there is a gap between laomei's software design philosophy and ours.
Ii. ASP. NET end (implementation of sending request end)
① Prepare the XML format. The sender and receiver agree the XML format. The content is omitted here ....
② Code implementation
Protected string sendrequestwhy (string strxml)
{
String STR = "";
// XML format agreed by both parties
Encoding encoding = encoding. utf8;
// Receiving page string strurl = "http: // 192.168.0.46: 8008/windchill/RF/JSP/material/gateway. jsp ";
Byte [] DATA = encoding. getbytes (strxml );
// Prepare the request...
Httpwebrequest myrequest = (httpwebrequest) webrequest. Create (strurl );
Myrequest. method = "Post ";
Myrequest. contenttype = "text/XML; charset = UTF-8 ";
Myrequest. contentlength = data. length;
// Identity authentication. Pay special attention to the parameter username and password.
Networkcredential cred = new networkcredential ("wcadmin", "wcadmin ");
Myrequest. Credentials = cred;
// Add verification information to the information request header. Otherwise, the verification fails.
Myrequest. preauthenticate = true;
Stream newstream = myrequest. getrequeststream ();
// Send data
Newstream. Write (data, 0, Data. Length );
Newstream. Close ();
Webresponse response = myrequest. getresponse ();
Stream resstream = response. getresponsestream ();
Streamreader sr = new streamreader (resstream, system. Text. encoding. utf8 );
STR = Sr. readtoend (); // receives the returned value. The returned value can be XML.
Resstream. Close ();
Sr. Close ();
Return STR;
}