u3d:关于u3d访问webservice服务的应用所遇到的问题

当把webservice服务写好之后,用本地ip测试,完整,没有问题,发布到服务器端,运行,有问题,无法访问,无法运行,报错。。。。。。。。。。。。。。

第一步:出现的问题,云服务器端开放了端口80端口,自己的端口设定的是随意的8083端口,没找到问题,询问了云服务器客服才知道没开端口,上网找资料,将自己设定的端口找到进行开放。

第二步:开了端口,继续用外网访问,问题依旧,网页报错500.119  没有web.config的访问权限,解决办法,删除了web.config,然后重新运行,会自动生成,依旧无效,检查所有的webservice文件,权限是让user用户完全控制,但是依旧没有效果,最后,将webservice的文件夹从自己域名指向的地方移动出来,最后好了,怎么解决的很莫名其妙

第三步:可以通过外网访问自己的webservice上的接口方法了,但是问题又来了,上一篇写的是通过http的post方法进行请求的,点开一个webservice页面上的方法,通常出现的是soap1.1  ,soap1.2和http post三个参考请求,然而因为第二步挖的坑,将web.config给删除了,所以默认情况下,没有开放http post请求,解决办法,最后在网上找到了web.config的配置方法,最后解决:

在运行WebService的网站中找到web.config并修改此文件:

1)找到节点<system.web></system.web>
2)在此节点里加入以下设置:
<webServices>
<protocols>
<add name="HttpPost" />
<add name="HttpGet" />
</protocols>
</webServices>
 
原文链接:https://www.xuebuyuan.com/2146967.html
根据上一篇的办法成功的请求交换到了数据
 
根据了解的两种访问webservice的接口办法,一种如上一篇
 string url= "http://192.168.2.1:8083/WebService1.asmx/Active";
    IEnumerator Upload()
    {
        WWWForm form = new WWWForm();
        form.AddField("code", "89080");
        UnityWebRequest request = UnityWebRequest.Post(url, form);
        yield return request.SendWebRequest();
        Debug.Log(request.error);
        Debug.Log(request.responseCode);
        Debug.Log(request.downloadHandler.text);
    }

方法比较简单,

第二种

  IEnumerator SoapHandler()
    {
        StringBuilder soap = new StringBuilder();
                        
        soap.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
        soap.Append("<soap12:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap12=\"http://www.w3.org/2003/05/soap-envelope\">");
        soap.Append("<soap12:Body>");
        soap.Append("<getWeather xmlns=\"http://WebXml.com.cn/\">");
        soap.Append("<theCityCode>深圳</theCityCode>");
        soap.Append("<theUserID></theUserID>");
        soap.Append("</getWeather>");
        soap.Append("</soap12:Body>");
        soap.Append("</soap12:Envelope>");

        WWWForm form = new WWWForm();
        var headers = form.headers;

        headers["Content-Type"] = "text/xml; charset=utf-8";
        headers["SOAPAction"] = "http://WebXml.com.cn/getWeather";
        headers["User-Agent"] = "gSOAP/2.8";

        WWW w = new WWW("http://ws.webxml.com.cn/WebServices/WeatherWS.asmx", Encoding.UTF8.GetBytes(soap.ToString()), headers);
        yield return w;
        if (w.isDone)
        {
            if (w.error != null)
            {
                print(w.error);
            }
            else
            {
                ParsingXml(w.text, Request_Type.SOAP);
            }
        }
    }
也就是http post和soap post两种不需要dll,
参考链接:https://www.cnblogs.com/fyluyg/p/6047819.html
 
 
 
 
 
 
 
 
 
 
 
 
 

猜你喜欢

转载自www.cnblogs.com/zbyglls/p/12111164.html