-1

I am using a service from a website for my private project.

I have a xml file like this one:

<Request Originator="xxxxx" Company="xxx">

    <Range Code="xx">

        <Item Id="xxxxxx-xxxxx-xxxxxx-xxx-7E8B94462F2C" />

    </Range>

    <KeyValues>

        <Translations>

            <Language Value="de" />

            <Language Value="en" />

        </Translations>

        <Regions Show="true" />

        <Towns Show="true" />

    </KeyValues>

</Request>

EDIT So for what i know till today: is one i send a request to this url: http://interface.deskline.net/DSI/KeyValue.asmx?WSDL With that server i make a communication but always get this error message:

soap:ReceiverSystem.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Xml.XmlException: Data at the root level is invalid. Line 1, position 1. at System.Xml.XmlTextReaderImpl.Throw(Exception e) at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace() at System.Xml.XmlTextReaderImpl.ParseDocumentContent() at System.Web.Services.Protocols.SoapServerProtocol.SoapEnvelopeReader.Read() at System.Xml.XmlReader.MoveToContent() at System.Web.Services.Protocols.SoapServerProtocolHelper.GetRequestElement() at System.Web.Services.Protocols.Soap12ServerProtocolHelper.RouteRequest() at System.Web.Services.Protocols.SoapServerProtocol.Initialize() at System.Web.Services.Protocols.ServerProtocolFactory.Create(Type type, HttpContext context, HttpRequest request, HttpResponse response, Boolean& abortProcessing) --- End of inner exception stack trace ---1

I don't get it the communication. and here is a little of the php code that i wrote:

$url = 'http://interfacetest.deskline.net/DSI/KeyValue.asmx';


$content = 0;
if (file_exists('/mm/request.xml')) {
    $xml = fopen('/mm/request.xml', "r");
    $content =  fread($xml,filesize("/mm/request.xml"));
    fclose($xml);
} else {
    echo 'No file, no request';
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
// Following line is compulsary to add as it is:
curl_setopt($ch, CURLOPT_POSTFIELDS,
    "xmlRequest=" . $content);
$response = curl_exec($ch);
echo $response;

1 Answers1

1

DOMDocument works great for manipulating XML documents, for example:

$domd=new DOMDocument();
$domd->formatOutput=true;
$domd->loadXML($str,LIBXML_NOBLANKS);
$rangeele=$domd->getElementsByTagName("Range")->item(0);
for($i=0;$i<5;++$i){
    $tmp=$domd->createElement("Item");
    $tmp->setAttribute("Id",$i);
    $rangeele->appendChild($tmp);
}
var_dump($domd->saveXML());

outputs

...
  <Range Code="xx">
    <Item Id="xxxxxx-xxxxx-xxxxxx-xxx-7E8B94462F2C"/>
    <Item Id="0"/>
    <Item Id="1"/>
    <Item Id="2"/>
    <Item Id="3"/>
    <Item Id="4"/>
  </Range>
...

quote how can I set up the communication between my server and theirs with php - that may be done several ways, depending on what the server support. the most common method is to communicate over the HTTP protocol (which by the way, is the same protocol your web browser primarily use to communicate with the stackoverflow.com website), which can be done like

$ch=curl_init('http://example.org/api');
curl_setopt_array($ch,array(CURLOPT_POST=>1,CURLOPT_HTTPHEADER=>array('Content-Type: application/xml'),CURLOPT_POSTFIELDS=>$xml));
curl_exec($ch);
curl_close($ch);

another popular method is to use the TCP protocol (of which the http protocol is built on top of), that can be done like

$sock=socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
socket_connect($sock,"example.org",1337);
socket_write($socket,$xml);
socket_close($sock);

there are plenty of other protocols too, ofc (and curl supports a great deal of them), but these are the most common ones. again, it really depends on what the target server supports, we at SO don't know, ask the guys you want to communicate with.

(ps, in the examples above, i omitted error checking. also, i downvoted and voted to close because your question is simply too broad, lacking details. you don't even explain what protocol you expect to use. quote I am trying for 2 hours to get this working but no luck. well, what have you tried? and how did it fail? )

hanshenrik
  • 19,904
  • 4
  • 43
  • 89