WFC RestFul webservice [英] WFC RestFul webservice

查看:91
本文介绍了WFC RestFul webservice的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用post方法做了一个安静的api,但是它显示了 没有找到Endpoint的错误。

这里是

file

i have made a a restful api using post method but it shows me the error that Endpoint not found.
here is the
file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;

namespace WcfService2
{

    [ServiceContract]
    public interface IRestTestService
    {//NeighbourhoodApi/?apiKey={apiKey}&lat={lat}&longg={longg}


        [OperationContract]
        [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json,RequestFormat=WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "NeighbourhoodApi/{apiKey}/{lat}/{longg}")]
        string NeighbourhoodApi(string apiKey, string lat, string longg);


    }

}





SVC档案



SVC File

using System;
using System.Collections.Generic;
using System.Linq;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Configuration;
using System.Web;
using System.Web.Services;
using System.Net;
using System.Web.Script.Serialization;
using System.Xml;
using System.IO;
using System.Xml.Linq;
using System.Xml.XPath;
using System.Xml.Serialization;

namespace WcfService2
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "RestTestService" in code, svc and config file together.
    // NOTE: In order to launch WCF Test Client for testing this service, please select RestTestService.svc or RestTestService.svc.cs at the Solution Explorer and start debugging.
    public class RestTestService : IRestTestService
    {
        public class neighbourHood
        {
            public neighbourHood()
            {

            }

            public string name { get; set; }
            public string vicinity { get; set; }
            public double latitude { get; set; }
            public double longitude { get; set; }

        }
        public string NeighbourhoodApi(string apiKey, string lat, string longg)
        {
          //  responseData objres = new responseData();
            string apikey = ConfigurationSettings.AppSettings["apiKey"];

            if (apiKey == apikey)
            {

            List<neighbourhood> lstNh = new List<neighbourhood>();
            neighbourHood objNeigh = new neighbourHood();
            JavaScriptSerializer jss = new JavaScriptSerializer();
            int indexCount = 0;
            string finaldata = string.Empty;

            //radius is given in meters so we have to give the radious in meters to get neigbhourhoods in ur curent location
            string url = "https://maps.googleapis.com/maps/api/place/nearbysearch/xml?location=" + lat + "," + longg + "&radius=5000&sensor=false&key=AIzaSyAhaD4HwgofkA2_9Z7fLbGB1V8Shi-S7do";
            WebRequest request = WebRequest.Create(url);

            try
            {

                using (WebResponse response = request.GetResponse())
                {
                    string res = string.Empty;
                    using (Stream stream = response.GetResponseStream())
                    {
                        using (StreamReader reader = new StreamReader(stream))
                        {
                            res = reader.ReadToEnd();
                        }

                        XmlDocument myDoc = new XmlDocument();
                        myDoc.LoadXml(res);
                        XmlElement root = myDoc.DocumentElement;
                        XmlNodeList objList = root.SelectNodes("/PlaceSearchResponse/result");
                        foreach (XmlNode name in objList)
                        {
                            objNeigh = new neighbourHood();

                            XmlNodeList objname = root.SelectNodes("/PlaceSearchResponse/result/name");
                            XmlNodeList objVicinity = root.SelectNodes("/PlaceSearchResponse/result/vicinity");
                            XmlNodeList objLat = root.SelectNodes("/PlaceSearchResponse/result/geometry/location/lat");
                            XmlNodeList objLong = root.SelectNodes("/PlaceSearchResponse/result/geometry/location/lng");

                            objNeigh.name = objname[indexCount].InnerText;
                            objNeigh.vicinity = objVicinity[indexCount].InnerText;
                            objNeigh.latitude = Convert.ToDouble(objLat[indexCount].InnerText);
                            objNeigh.longitude = Convert.ToDouble(objLong[indexCount].InnerText);

                            lstNh.Add(objNeigh);
                            indexCount++;
                        }

                    }

                    bool result;

                    if (res != null)
                    {
                        result = true;
                        //res = res.Replace("/", "");
                        //res = res.Replace("+", "");
                    }
                    else
                    {
                        result = false;
                    }
                    string abc ="{" + '"' + "Head" + '"' + ":{" + '"' + "Status" + '"' + ":" + jss.Serialize(result) + "}," + '"' + "Body" + '"' + ":" + jss.Serialize(lstNh) + "}";
                    return abc;
                   
                }
            }
            catch (Exception e)
            {
                string error = "Please enter a valid latitude and longitude";
                return error;
               
            }
            }
            else
            {
             
                string error = "Api is not valid testing";
                return error; 
            }
        }

       
    }
}



和web .config文件


and the web .config file

<?xml version="1.0"?>
<configuration>
  <appSettings>
    <add key="apiKey" value="59AB8FB9-E60D-4FC8-9F10-80330AAFD741"/>
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
    <httpRuntime/>

  <customErrors mode="Off">

  </customErrors>
  </system.web>
  <system.serviceModel>
    <services>
      <service name="WcfService2.RestTestService" behaviorConfiguration="ServiceBehaviour">
        <!-- Service Endpoints -->
        <!-- Unless fully qualified, address is relative to base address supplied above -->
        <endpoint address="" binding="webHttpBinding" contract="WcfService2.IRestTestService" behaviorConfiguration="web">
          <!--
              Upon deployment, the following identity element should be removed or replaced to reflect the
              identity under which the deployed service runs.  If removed, WCF will infer an appropriate identity
              automatically.
          -->
        </endpoint>

      </service>
    </services>
    <behaviors>
      <serviceBehaviors>
        <behavior name="ServiceBehaviour">
          <!-- To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment -->
          <serviceMetadata httpGetEnabled="true"/>
          <!-- To receive exception details in faults for debugging purposes, set the value below to true.  Set to false before deployment to avoid disclosing exception information -->
          <serviceDebug includeExceptionDetailInFaults="false"/>
        </behavior>
      </serviceBehaviors>
      <endpointBehaviors>
        <behavior name="web">
          <webHttp/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment multipleSiteBindingsEnabled="true" />
  </system.serviceModel>
  <system.webServer>
    <modules runAllManagedModulesForAllRequests="true"/>
  </system.webServer>
</configuration>





任何人都可以帮助我

推荐答案

wcf-endpoint-not-found [ ^ ]



wcf-rest-service-endpoint-not-found [ ^ ]



endpoint-not-found-error-in-rest-wcf-service [ ^ ]



查看此链接..希望你能够实现它。
wcf-endpoint-not-found[^]

wcf-rest-service-endpoint-not-found[^]

endpoint-not-found-error-in-rest-wcf-service[^]

Check this links..hope you will able to make it out.


这篇关于WFC RestFul webservice的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆