0
I would like to add an reference for WCF weather forecast webservice in my application.The thing is I have done everything correctly,but i am lacking somewhere else.It throws an Exception.The Exception message is in the bottom of this post.Somebody out there please help me to fix this.Unles or until fixing this i couln't move to the next phase.

我的源代码在这里:

public partial class Testing : System.Web.UI.Page
    {
        weather.WeatherForecastServiceClient ws = new weather.WeatherForecastServiceClient();
        protected void Page_Load(object sender, EventArgs e)
        {
            SortedDictionary<string, string> objDic = new SortedDictionary<string, string>();
            foreach (CultureInfo ObjectCultureInfo in CultureInfo.GetCultures(CultureTypes.SpecificCultures))
            {
                RegionInfo objRegionInfo = new RegionInfo(ObjectCultureInfo.Name);
                if (!objDic.ContainsKey(objRegionInfo.EnglishName))
                {
                    objDic.Add(objRegionInfo.EnglishName, ObjectCultureInfo.Name);
                }
            }
        foreach (KeyValuePair<string, string> val in objDic)
        {
            Country.Items.Add(new ListItem(val.Key, val.Value));
        }

    }

    protected void callwebservice_Click(object sender, EventArgs e)
    {

            Result.Text = "Result" + ws.GetForecastByCity(City.SelectedItem.ToString(), Country.SelectedItem.ToString());

    }

    protected void Country_SelectedIndexChanged(object sender, EventArgs e)
    {
        string[] cities = ws.GetCitiesByCountry(Country.SelectedItem.ToString());
        City.DataSource = cities;
        City.DataBind();
    }
}

这是我的例外

    Server Error in '/' Application.

    **The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 
    Exception Details: System.ServiceModel.FaultException: The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.
    Source Error: 
    Line 310:        
    Line 311:        public testing.weather.Weather GetForecastByCity(string City, string Country) {
    Line 312:            return base.Channel.GetForecastByCity(City, Country);
    Line 313:        }
    Line 314:    }
Source File: E:\***\WeatherForecast\testing\Service References\weather\Reference.cs    Line: 312 

Stack Trace: 


[FaultException: The server was unable to process the request due to an internal error.  For more information about the error, either turn on IncludeExceptionDetailInFaults (either from ServiceBehaviorAttribute or from the <serviceDebug> configuration behavior) on the server in order to send the exception information back to the client, or turn on tracing as per the Microsoft .NET Framework 3.0 SDK documentation and inspect the server trace logs.]
   System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg) +9442991
   System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) +345
   testing.weather.IWeatherForecastService.GetForecastByCity(String City, String Country) +0
   testing.weather.WeatherForecastServiceClient.GetForecastByCity(String City, String Country) in E:\sasi\WeatherForecast\testing\Service References\weather\Reference.cs:312
   testing.Testing.callwebservice_Click(Object sender, EventArgs e) in E:\sasi\WeatherForecast\testing\Testing.aspx.cs:40
   System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563

Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272**
4

1 回答 1

0

您已正确实施该服务。您可以通过运行来确认这一点GetCitiesByCountry(它将返回一个城市列表)。只是该方法GetForecastByCity目前不起作用。

请尝试使用这些 API中的任何一个。

于 2013-08-06T10:27:34.823 回答