Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/269.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从Soap调用到UPNP TV的请求不正确_C#_Soap_Upnp_Dlna - Fatal编程技术网

C# 从Soap调用到UPNP TV的请求不正确

C# 从Soap调用到UPNP TV的请求不正确,c#,soap,upnp,dlna,C#,Soap,Upnp,Dlna,我一直在玩向支持Upnp的电视发送命令的游戏。我已经编写了一些C代码来请求网络上的UPNP设备,然后通过soap向电视发送命令。然而,当我向电视提出请求时,我总是收到400个坏请求。我看了《小提琴手》,这似乎是一个原始的要求 POST http://192.168.1.4:52323/upnp/control/RenderingControl HTTP/1.1 SOAPACTION: urn:schemas-upnp-org:service:RenderingControl:1#SetVolum

我一直在玩向支持Upnp的电视发送命令的游戏。我已经编写了一些C代码来请求网络上的UPNP设备,然后通过soap向电视发送命令。然而,当我向电视提出请求时,我总是收到400个坏请求。我看了《小提琴手》,这似乎是一个原始的要求

POST http://192.168.1.4:52323/upnp/control/RenderingControl HTTP/1.1 SOAPACTION: urn:schemas-upnp-org:service:RenderingControl:1#SetVolume Content-Type: text/xml;charset="utf-8" Accept: text/xml Host:
192.168.1.4:52323 Content-Length: 418 Expect: 100-continue Connection: Keep-Alive

<?xml version="1.0" encoding="utf-8"?> <s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">   <s:Body>
    <ns0:SetVolume xmlns:ns0="urn:schemas-upnp-org:service:RenderingControl:1">
      <InstanceId>0</InstanceId>
      <Channel>Master</Channel>
      <DesiredVolume>70</DesiredVolume>
    </ns0:SetVolume>   </s:Body> </s:Envelope>
已更新

我试图删除所有代码,只是通过fiddler形成请求。我目前没有把电视连接到我的网络上,所以我正在尝试测试对我的路由器的呼叫。这是我通过fiddler新构造的调用:

POST http://10.0.0.1:49153/upnp/control/Layer3Forwarding HTTP/1.1
SOAPACTION: urn:schemas-upnp-org:service:Layer3Forwarding:1#GetDefaultConnectionService
Content-Type: text/xml;charset="utf-8"
Host: 10.0.0.1:49153
Content-Length: 345

<?xml version="1.0" encoding="utf-8"?>
<s:Envelope s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Body>
    <ns0:GetDefaultConnectionService xmlns:ns0="urn:schemas-upnp-org:service:Layer3Forwarding:1">
    </ns0:GetDefaultConnectionService>
  </s:Body>
</s:Envelope>
POSThttp://10.0.0.1:49153/upnp/control/Layer3Forwarding HTTP/1.1
SOAPACTION:urn:schemas upnp org:service:Layer3Forwarding:1#GetDefaultConnectionService
内容类型:text/xml;charset=“utf-8”
主持人:10.0.0.1:49153
内容长度:345
但是,我不断收到无效的操作报告或错误的xml,例如下面的响应:

HTTP/1.1 500 Internal Server Error
CONTENT-LENGTH: 413
CONTENT-TYPE: text/xml; charset="utf-8"
DATE: Tue, 14 Mar 2017 21:55:49 GMT
EXT: 
SERVER: Linux/3.12.14, UPnP/1.0, Portable SDK for UPnP devices/1.6.18
X-User-Agent: redsonic

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<s:Body>
<s:Fault>
<faultcode>s:Client</faultcode>
<faultstring>UPnPError</faultstring>
<detail>
<UPnPError xmlns="urn:schemas-upnp-org:control-1-0">
<errorCode>-111</errorCode>
<errorDescription>Invalid Action</errorDescription>
</UPnPError>
</detail>
</s:Fault>
</s:Body>
</s:Envelope>
HTTP/1.1500内部服务器错误
内容长度:413
内容类型:text/xml;charset=“utf-8”
日期:2017年3月14日星期二21:55:49 GMT
提取:
服务器:Linux/3.12.14、UPnP/1.0、用于UPnP设备的便携式SDK/1.6.18
X用户代理:redsonic
s:客户
UPnPError
-111
无效动作
关于我的请求如何失败有什么想法吗?

UPnP声明操作调用的格式是

POST path of control URL HTTP/1.1
HOST: host of control URL:port of control URL
CONTENT-LENGTH: bytes in body
CONTENT-TYPE: text/xml; charset="utf-8"
SOAPACTION: "urn:schemas-upnp-org:service:serviceType:v#actionName"

<?xml version="1.0"?>
< s:Envelope
  xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
  s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <s:Body>
    <u:actionName xmlns:u="urn:schemas-upnp-org:service:serviceType:v">
      <argumentName>in arg value</argumentName>
       other in args and their values go here, if any
    </u:actionName>
  </s:Body>
</s:Envelope>
控件URL HTTP/1.1的发布路径 主机:控制主机URL:控制端口URL CONTENT-LENGTH:正文中的字节 内容类型:text/xml;charset=“utf-8” SOAPACTION:“urn:schemas upnp组织:服务:服务类型:v#actionName” 以arg值表示 其他参数及其值(如果有的话)在这里 您的代码在以下几个方面与此不同:

  • HTTP头之间没有换行符(
    \r\n
    )(除非您的问题中存在格式错误)
  • POST
    标题中的路径不应包含方案、主机或端口。i、 e.删除
    http://192.168.1.4:52323

您可能还想考虑删除<代码>预期标头。添加它似乎没有任何好处(您不应该期望在本地网络上遇到任何支持此标头但无法处理数百字节请求正文开销的服务器/代理)。相反,您完全可能会遇到原始HTTP服务器,它们不知道如何处理此标头,因此拒绝请求。

谢谢您提供的信息!我认为标题之间有新行,这只是从fiddler复制过来的格式问题。我编辑了原始帖子,以展示我是如何用C#构建webRequest的。我可以尝试删除expect标头并修复我的帖子值。将帖子行中的
control/Layer3Forwarding
切换到
Layer3Forwarding/control
怎么样?这就是我的设备上的样子。谢谢你的建议,我想我的问题是我的SOAPACTION没有被引用。我现在似乎得到了小提琴手的回应。Device Spy在追踪我的请求和格式正确的请求之间的差异方面帮了大忙。
POST path of control URL HTTP/1.1
HOST: host of control URL:port of control URL
CONTENT-LENGTH: bytes in body
CONTENT-TYPE: text/xml; charset="utf-8"
SOAPACTION: "urn:schemas-upnp-org:service:serviceType:v#actionName"

<?xml version="1.0"?>
< s:Envelope
  xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"
  s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
  <s:Body>
    <u:actionName xmlns:u="urn:schemas-upnp-org:service:serviceType:v">
      <argumentName>in arg value</argumentName>
       other in args and their values go here, if any
    </u:actionName>
  </s:Body>
</s:Envelope>