This time I made a tax control interface on the socket method. Sadly, their interface documentation is always immature and there are various errors.
First, let's talk about what you need to pay attention.
First, pay attention to the format of XML strings transmitted by socket. Otherwise, Chinese characters may be garbled.
/// <Summary>
/// Send XML data
/// </Summary>
/// <Param name = "XML"> </param>
/// <Param name = "ip"> </param>
/// <Param name = "Port"> </param>
/// <Returns> send XML data results </returns>
Public String socketgetxml (string XML, string IP, string port)
{
Byte [] result = new byte [1024];
IPaddress ipadress = IPaddress. parse (IP );
Socket clientsocket = new socket (addressfamily. InterNetwork, sockettype. Stream, protocoltype. TCP );
Clientsocket. Connect (New ipendpoint (ipadress, convert. toint32 (port )));
Clientsocket. Send (encoding. getencoding ("gb2312"). getbytes (XML ));
Thread. Sleep (1000 );
Int incluelength = clientsocket. Receive (result );
Clientsocket. Close ();
Return encoding. getencoding ("gb2312"). getstring (result, 0, cancelength );
}
Second, attention should be paid to the problem of passing Chinese parameters in a modal window.
In front-end JS:
VaR message = Window. showmodaldialog ("invoicecharge. aspx? KPR = "+ encodeuri (KPR) +" & je = "+ je +" & invoversion = "+ invoversion +" & invonumber = "+ fph ,"", "dialogheight: 100px; dialogwidth: 200px; Status: No; center: Yes ;");
Background C # Processing Time:
String KPR = httputility. urldecode (request ["KPR"]);
String je = request ["Je"];
String invoversion = request ["invoversion"];
String invonumber = request ["invonumber"];
However, if the passed parameter contains special symbols such as-or %, it cannot be parsed. You can use encodeuricomponent (parameters) to convert the data at the front end.
Third: Values of the modal form:
You can pass the value to a hidden domain in the C # background,
At the same time, you can use js to obtain the value at the front end of the page, but this JS must be loaded in the onload of the body. For example:
<Script language = "JavaScript" type = "text/JavaScript">
Function onload (){
VaR messsage = Document. getelementbyid ("hiddenfield2"). value;
Window. returnvalue = messsage;
Window. Close ();
}
</SCRIPT>
</Head>
<Body onload = "onLoad ();">
Fourth: About parsing XML strings in Js.
First, convert the XML string to an XML object. Then parse
// Convert a string to an XML Object
Function toxmldom (source ){
VaR xmldoc = NULL;
If (window. activexobject ){
VaR arr_activex = ["msxml4.domdocument", "msxml3.domdocument", "msxml2.domdocument", "MSXML. domdocument", "Microsoft. xmldom"];
VaR xmldomflag = false;
For (VAR I = 0; I <arr_activex.length &&! Xmldomflag; I ++ ){
Try {
VaR objxml = new activexobject (arr_activex [I]);
Xmldoc = objxml; xmldomflag = true;
} Catch (e ){}
} If (xmldoc ){
Xmldoc. async = false;
Xmldoc. loadxml (source );
}
} Else {
VaR parser = new domparser ();
VaR xmldoc = parser. parsefromstring (source, "text/XML ");
}
Return xmldoc;
}
This is a conversion method suitable for various browsers and is compatible with IE and Firefox.
Then:
Function getattributevalue (xmlnode, attrname ){
If (! Xmlnode) Return "";
If (! Xmlnode. attributes) Return "";
If (xmlnode. attributes [attrname]! = NULL)
Return xmlnode. attributes [attrname]. value;
If (xmlnode. Attributes. getnameditem (attrname )! = NULL)
Return xmlnode. Attributes. getnameditem (attrname). value; Return "";
}
This is to obtain the attribute value of the corresponding node.
VaR xmldoc = new activexobject ("Microsoft. xmldom ");
Xmldoc. async = "false ";
Xmldoc. loadxml (arybill [I]);
VaR je = (getattributevalue (xmldoc. getelementsbytagname ("item") [0]. childnodes [55], "value ")). split (':') [1]. tostring ();
VaR KPR = (getattributevalue (xmldoc. getelementsbytagname ("item") [0]. childnodes [70], "value ")). split ('') [0]. tostring ();
VaR fpbbh = invoversion;
VaR fph = getattributevalue (xmldoc. getelementsbytagname ("item") [0]. childnodes [95], "value ");
This is how to obtain the value.
Summary of tax control issues