1.因为我的webservice返回的是json,

2.ajax传递跨域不安全,

3.contentType: "application/json; charset=utf-8", 这个是直接访问的webservice

 

所以还是采用后台调用

如果引用微软的webService直接new对象,调用方法,就会报错根级别上的数据无效

困扰了我1天,最后的解决方法,

创建辅助类,

    public class WebServiceHelper
{
/// <summary>
///
/// </summary>
/// <param name="url">地址</param>
/// <param name="method">方法</param>
/// <param name="param">json参数</param>
/// <returns></returns>
public static string WebServiceApp(string url, string method, string param)
{
byte[] byteArray = Encoding.UTF8.GetBytes("json=" + param);
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri(url + "/" + method));
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.ContentLength = byteArray.Length;
Stream newStream = webRequest.GetRequestStream();
newStream.Write(byteArray, 0, byteArray.Length);
newStream.Close();
HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
StreamReader php = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
string phpend = php.ReadToEnd(); return phpend;
}
}

 

 

 

调用方法:

WebService – 3.后台调用WebService,根级别上的数据无效的更多相关文章

  1. LoadXml 加载XML时,报错:“根级别上的数据无效。 行1,位置1“

    ==XML=================================== <?xml version="1.0" encoding="utf-8" ...

  2. C# XML 根级别上的数据无效

    XmlDocument加载xml方法 XmlDocument doc = new XmlDocument(); //加载xml 字符串 doc.LoadXml(_Store); //加载xml文件 d ...

  3. C#.NET LoadXml 时 “根级别上的数据无效。 行 1,位置 1”

    去除XML HEADER: <?xml version="1.0" encoding="utf-8"?> if (rspBusiXml.Contai ...

  4. 微信的API都是通过https调用实现的,分为post方法调用和get方法调用。不需要上传数据的采用get方法(使用IntraWeb开发)

    首先需要明确的是,微信的API都是通过https调用实现的,分为post方法调用和get方法调用.不需要上传数据的采用get方法(例如获取AccessToken),而需要向微信服务器提交数据的采用po ...

  5. 在windows后台调用webservice

    1.首先要创建个webservice,然后再webservice写一个方法如图 2.然后将WebService1.asmx 在浏览器中浏览会出现如图所示(该地址很重要,复制此地址在下边程序中要用到) ...

  6. WebService – 2.动态调用WebService

    在本节课程中,将演示如何通过程序动态添加.调用.编译.执行WebService并返回结果. WebService动态调用示意图 WebService相关知识 代码文档对象模型CodeDom的使用 编程 ...

  7. C# 不用添加WebService引用,调用WebService方法

    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行. [System.Web.Script.Services.ScriptService] 使用HttpWeb ...

  8. 搭建调用 WebService 的 ASP.NET 网站 (VS2010, C#)

    [系统环境]Windows 7 / 2008r2 [软件环境]Visual Studio 2010 [开发语言]C# [感谢]本文是在 <C#开发和调用Web Service> 一文的基础 ...

  9. 异步调用webservice

    一.异步调用 asynchronous call(异步调用):一个可以无需等待被调用函数的返回值就让操作继续进行的方法 举例: 异步调用就是你 喊 你朋友吃饭 ,你朋友说知道了 ,待会忙完去找你 ,你 ...

随机推荐

  1. [lintcode 14] First Position of Target

    For a given sorted array (ascending order) and a target number, find the first index of this number ...

  2. [TimusOJ1057]Amount of Degrees

    [TimusOJ1057]Amount of Degrees 试题描述 Create a code to determine the amount of integers, lying in the ...

  3. class training

    实验3-1 分别使用while循环.do while循环.for循环求 (即求1+2+3+ --+100). 参考: 源码 方法一#include<stdio.h> int main(){ ...

  4. 模式串匹配,kmp

    #include <stdio.h> #include <stdlib.h> #include <string> #include<string.h> ...

  5. Oauth 2.0第三方账号登录原理图

    百度.QQ等服务商

  6. How can I determine the URL that a local Git repository was originally cloned from?

    git remote show origin from: http://stackoverflow.com/questions/4089430/how-can-i-determine-the-url- ...

  7. meteor 为基础,联合 Apollo + React + React-Router

    Graphql with Apollo, Meteor and React: https://janikvonrotz.ch/2016/10/09/graphql-with-apollo-meteor ...

  8. FREE 开源 API 管理工具等

    最近学习API 管理工具,发现几个不错的东西,记录如下: 1.IBM 收购NODE 厂家  STRONGLOOP 有一产品LOOPBACK,开源,好! 2.apigee  api管理平台 也不错. 3 ...

  9. logging模块使用示例

    日志等级说明: UNSET < DEBUG < INFO < WARNNING < ERROR  < CRITICAL import logging logger = l ...

  10. 使用logrotate管理nginx日志文件

    本文转载自:http://linux008.blog.51cto.com/2837805/555829 描述:linux日志文件如果不定期清理,会填满整个磁盘.这样会很危险,因此日志管理是系统管理员日 ...