WCF不尊重RequestFormat

时间:2017-12-30 16:25:09

标签: c# wcf

尝试创建一个充当restful端点的简单WCF服务。希望有人能看到我失踪的东西。

[OperationContract]
[WebInvoke(Method ="POST", UriTemplate = "TestJson", BodyStyle = WebMessageBodyStyle.Wrapped, RequestFormat = WebMessageFormat.Json, ResponseFormat = WebMessageFormat.Json)]
        string TestJson(CompositeType composite);

从邮递员那里得到

  

无法处理邮件,因为内容类型' application / json'不是预期的&text; / xml;字符集= UTF-8'

1 个答案:

答案 0 :(得分:0)

我猜你的web.config文件有问题。您应该为肥皂服务添加basicHttpBinding,为webHttpBinding添加mexHttpBinding以获得宁静的服务。如果你想要它们,你也应该添加<bindings> <basicHttpBinding> <binding name="SoapBinding" /> </basicHttpBinding> <webHttpBinding> <binding name="RestBinding" /> </webHttpBinding> <mexHttpBinding> <binding name="MexBinding" /> </mexHttpBinding> </bindings> 。像这样的东西:

    <endpointBehaviors>
        <behavior name="Web">
            <webHttp helpEnabled="true" defaultBodyStyle="Bare" defaultOutgoingResponseFormat="Json" automaticFormatSelectionEnabled="true" />
        </behavior>
    </endpointBehaviors> 

然后您可以将json格式设置为默认格式,如下所示:

# The video 'SixtyFPS.mov' was recorded on an iPhone 7 at 60 FPS
# The video has a length of roughly 4 seconds long and so the total number
# of frames should be ~240, however my number_of_frames variable is equal to 115
# I am looking for a way to restart the video once it has reached its end but 
# I have not yet discovered a good method for doing so. Any advice would be 
# greatly appreciated. I am using Python 3.6.4 and OpenCV 3.3.1
# I needed to rotate the video so that it would be viewed in portrait 
# orientation rather than landscape


import cv2
import numpy as np

# Load in the video
video_cap = cv2.VideoCapture('SixtyFPS.mov')

# display the total number of frames. Should be ~240 and not 115
number_of_frames = int(video_cap.get(cv2.CAP_PROP_FRAME_COUNT))
print("The total number of frames is: " + str(number_of_frames))

# Check if video opened successfully
if (video_cap.isOpened() == False):
    print("Error opening video file")

frame_counter = 0

# Read until video is completed
while(video_cap.isOpened()):
    # Capture frame-by-frame
    ret, frame = video_cap.read()
    if ret == True:

        frame_counter += 1

        # resize the window
        resized_vid = cv2.resize(frame, (720, 1280))

        # Convert the video to grayscale
        grayscale_vid = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

        # Change the orientation from landscape to portrait by rotating
        (h, w) = grayscale_vid.shape[:2]
        center = (w / 2, h / 2)
        M = cv2.getRotationMatrix2D(center, 270, 1.0)
        rotated_video = cv2.warpAffine(grayscale_vid, M, (w, h))

        # Display the rotated video
        cv2.imshow('Pitch', rotated_video)

        # trying to restart the video when the frame_counter
        # reaches its maximum value of 110
        if frame_counter >= 110:
            # here is where I think I need to restart the video
            # by setting the current frame to zero 


        # Press Q on keyboard to exit
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    # Break the loop
    else: 
        break

# When everything done, release the video capture object
video_cap.release()

# Closes all the frames
cv2.destroyAllWindows()
现在你很高兴。只需记住在请求标题中设置content-type。