Notification Hub Rest API - 指定的资源描述无效

时间:2016-10-19 18:45:46

标签: c# azure xmldocument dotnet-httpclient azure-notificationhub

好的,所以当我尝试对其余的api进行创建注册调用时,我收到错误“指定的资源描述无效”。

我认为xml正文有问题但是在使用postman进行测试时它可以工作,所以我可能在使用loadXml或者sendAsync做错了吗?

这是我正在使用的代码。

 client.BaseAddress = new Uri("https://myservicehub.servicebus.windows.net");
            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Add("x-ms-version", "2015-01");
            client.DefaultRequestHeaders.Add("Authorization", sasToken);
            HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, "/myservicehub/registrations/?api-version=2015-01");

             XmlDocument doc = new XmlDocument();

             doc.LoadXml("<entry xmlns='http://www.w3.org/2005/Atom'>" +
                 "<content type='application/xml'>"+
                 "<AppleRegistrationDescription xmlns:i='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://schemas.microsoft.com/netservices/2010/10/servicebus/connect'>"+
                 "<Tags>user</Tags>"+
                 "<DeviceToken>EEEEEE</DeviceToken>" +
                 "</AppleRegistrationDescription>"+
                 "</content>"+
                 "</entry>");

            request.Content = new StringContent(doc.ToString(), Encoding.UTF8, "application/atom+xml");

            HttpResponseMessage response = await client.SendAsync(request);

邮递员要求

PostUrl:https://myservicehub.servicebus.windows.net/myservicehub/registrations/?api-version=2015-01



 <?xml version='1.0' encoding='utf-8'?>
<entry xmlns='http://www.w3.org/2005/Atom'>
    <content type='application/xml'>
        <AppleRegistrationDescription xmlns:i='http://www.w3.org/2001/XMLSchema-instance' xmlns='http://schemas.microsoft.com/netservices/2010/10/servicebus/connect'>
            <Tags>user</Tags>
            <DeviceToken>EEEEEE</DeviceToken>
        </AppleRegistrationDescription>
    </content>
</entry>

那么我做错了什么?

最佳, 罗宾

1 个答案:

答案 0 :(得分:0)

由于Dmitry P.解决了这个问题。问题出现在这一行

 request.Content = new StringContent(doc.OuterXml, Encoding.UTF8, "application/atom+xml");

将其更改为:

*.bsp