1

この JavaScript コードを実行すると、「0x800a1391 - JavaScript ランタイム エラー: 'InputService' は未定義です」と表示されます。

私は試してみましたが、欠けているものを理解できないようです...

Web.Config ファイル (Web サービス部分のみ):

  <system.serviceModel>
    <behaviors>
      <endpointBehaviors>
        <behavior name="CommonEndPointBehavior">
          <enableWebScript/>
        </behavior>
      </endpointBehaviors>
    </behaviors>
    <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
    <services>
      <service name="InputService">
        <endpoint name="" address="" behaviorConfiguration="CommonEndPointBehavior" binding="webHttpBinding" contract="InputService" bindingConfiguration="webBinding" />
      </service>
    </services>
    <bindings>
      <webHttpBinding>
        <binding name="webBinding">
          <!--<security mode="Transport">-->
          <security mode="None"/>
        </binding>
      </webHttpBinding>
    </bindings>
  </system.serviceModel>

サービス:

[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class InputService
{
[OperationContract]
public string EditSiteElement(int siteid, string name, string url, string description, int siteorder, bool active)
{
    return Input.EditSiteElement(siteid, name, url, description, siteorder, active);
}
}

Web フォームの参照:

    scriptManagerProxy.Services.Add(new ServiceReference("~/User/Input.svc"));
    scriptManagerProxy.Scripts.Add(new ScriptReference("~/User/Input.js"));

JavaScript ファイル:

//When edit button is clicked on row.
function EditSiteElement(siteid) {
    InputService.GetSiteIdInfo(siteid, function (result) {
        var stuff = result.split('¤');
        $('[id$=TextBox_name]').val(stuff[0]);
        $('[id$=TextBox_link]').val(stuff[1]);
        $('[id$=TextBox_description]').val(stuff[2]);
        $('[id$=CheckBox_active]').prop('checked', (stuff[3] == 'True'));
        $('[id$=TextBox_order]').val(stuff[4]);
        //Open the dialog
        $("[id$=panel_Input]").dialog('open');

        SiteIdForSave = siteid;
    });
}
4

1 に答える 1

0

そのため、いくつかの変更を行う必要があります。

最初に、名前空間WebInvokeに存在する属性でサービス メソッドを装飾しSystem.ServiceModel.Webます (プロジェクトへの参照を追加する必要がある場合があります)。

[OperationContract]
[System.ServiceModel.Web.WebInvoke] //add this attribute
public string EditSiteElement(int siteid, string name, string url, string description, int siteorder, bool active)
{
    return Input.EditSiteElement(siteid, name, url, description, siteorder, active);
}

次に、InputService.svcファイル (Visual Studio でファイルを右クリックしてInputService.svcを選択) に属性View Markupを追加します。Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory"

<%@ ServiceHost Language="C#" Debug="true" Factory="System.ServiceModel.Activation.WebScriptServiceHostFactory" Service="WebApplication6.InputService" CodeBehind="InputService.svc.cs" %>

アプリケーションのターゲット フレームワークのバージョンが4.5であることを確認してください。

[編集]

web.config<system.serviceModel>セクションを次のように変更することをお勧めします。MyNamespace名前空間 ( ) の使用と、動作定義をエンド ポイントからサービス レベルに移動したことに注意してください。

<system.serviceModel>
  <behaviors>
    <serviceBehaviors>
      <behavior name="InputServiceBehavior">
        <serviceMetadata httpGetEnabled="true"/>
        <serviceDebug includeExceptionDetailInFaults="false"/>
      </behavior>
    </serviceBehaviors>
  </behaviors>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" multipleSiteBindingsEnabled="true"/>
  <services>
    <service behaviorConfiguration="InputServiceBehavior" name="MyNamespace.InputService">
      <endpoint address="" binding="webHttpBinding" contract="MyNamespace.InputService" bindingConfiguration="webBinding"/>
    </service>
  </services>
  <bindings>
    <webHttpBinding>
      <binding name="webBinding">
        <!--<security mode="Transport">-->
        <security mode="None"/>
      </binding>
    </webHttpBinding>
  </bindings>
</system.serviceModel>
于 2012-12-16T17:28:36.710 に答える